-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbackup-web
More file actions
executable file
·43 lines (36 loc) · 779 Bytes
/
backup-web
File metadata and controls
executable file
·43 lines (36 loc) · 779 Bytes
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
39
40
41
42
#!/bin/sh
# backup web nightly to remote server
option_install()
{
[ -z "$1" ] && echo "No destination specified" && exit 1
MIN=`expr $RANDOM % 60`
HOUR=1
echo "$MIN $HOUR * * * root $0 backup $1" >> /etc/crontab
exit
}
option_uninstall()
{
sed -i "/$0/d" /etc/crontab && exit
}
backup_list()
{
echo '/var/www'
ls -1 /var/lib/mysql/*.backup |sed 's/.backup//'
}
option_backup()
{
[ -z "$1" ] && echo "No destination specified" && exit 1
TGZ="web-backup-`date '+%F'`.tgz"
tar cfz /tmp/$TGZ `backup_list`
scp /tmp/$TGZ $1
}
if [ -z "$1" ]
then
echo "use: $0 install (scp target path) - adds nightly cronjob"
echo " $0 uninstall - remove cronjob"
echo " $0 backup (scp target path) - manual run"
exit
fi
OPT="$1"
shift
option_$OPT $*