-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlinux_tvheadend_server_backup_and_restore
executable file
·38 lines (33 loc) · 1.99 KB
/
linux_tvheadend_server_backup_and_restore
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
# Script to backup and restore TVHeadend server configuration on Linux, Rapberry Pi/Raspbian. Process will cause TVH to restart during the task.
# setup: sudo su;cd;chmod 750 linux_tvheadend_server_backup_and_restore;crontab -e;append line to run backup every 6 months (make sure path exist):
# 0 0 0 */6 * /bin/bash /root/linux_tvheadend_server_backup_and_restore backup 2&1>/dev/null
# Run backup/restore manually:
# A) ./linux_tvheadend_server_backup_and_restore backup
# B) ./linux_tvheadend_server_backup_and_restore restore
# to restore backup on a new installation, place your backup file manually to location like this: /home/hts/.hts/tvheadend_backup.tar
# to enable e-mailing of the backup, type yes into appropriate variable below. Note that the script will then install mutt and sendmail service! (+10MB of disk space maybe). Check /var/log/maillog
sendbackupviaemail=""
email=""
service_name=tvheadend
default_home_dir=/home/hts
if [[ "$1" == "" ]];then echo "You need to run this script with parameter backup or restore (example: ./thisscriptname backup)" && exit;fi
[ -r /etc/default/$service_name ] && . /etc/default/$service_name
[ -z "$TVH_USER" ] || eval home_dir=~$TVH_USER
[ -z "$home_dir" ] && home_dir=$default_home_dir
if [[ "$1" == "backup" ]];then
service tvheadend stop
mv -f $home_dir/.hts/tvheadend_backup.tar $home_dir/.hts/tvheadend_backup_previous.tar 2>/dev/null
tar -cpf $home_dir/.hts/tvheadend_backup.tar -C $home_dir/.hts/ tvheadend
service tvheadend start
if [[ "$sendbackupviaemail" == "yes" ]];then
apt-get install mutt sendmail -y 2>/dev/null||yum install mutt sendmail -y 2>/dev/null
echo "Made on $(hostname) on $(date --rfc-3339=date)"|mutt -s "TVHeadend server configuration backup" -a $home_dir"/.hts/tvheadend_backup.tar" -- "$email"
fi
fi
if [[ "$1" == "restore" ]];then
service tvheadend stop
mv -f $home_dir/.hts/tvheadend $home_dir/.hts/tvheadend_before_last_restore 2>/dev/null
tar -xpf $home_dir/.hts/tvheadend_backup.tar -C $home_dir/.hts/
service tvheadend start
fi