bin sh cron root root adm backup sh BACKUP_DIR backup fs FILES_SRC roo

 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
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh
# cron: 0 3 * * * root /root/adm/backup.sh
BACKUP_DIR=/backup/fs
FILES_SRC=/root/adm/backup_src.lst
INCLUDE_FILES_PATTERN=/root/adm/backup_include.lst
EXCLUDE_FILES_PATTERN=/root/adm/backup_exclude.lst
BACKUP_DB_DIR=/backup/db
DB_BACKUP_PREFIX=db
MYSQL_HOST=localhost
MYSQL_USER=user
MYSQL_PASSWD=password
TIMESTAMP=`date '+%Y%m%d-%H%M%S'`
DAY=`date '+%d'`
FULL_BACKUP_DIR=$BACKUP_DIR/current
INC_BACKUP_DIR=$BACKUP_DIR/$DAY\_$TIMESTAMP
rm -f -R $BACKUP_DIR/$DAY\_*
nice -n 10 rsync -r --force --ignore-errors --delete --delete-excluded -av \
--backup --backup-dir=$INC_BACKUP_DIR \
--exclude-from=$EXCLUDE_FILES_PATTERN \
--include-from=$INCLUDE_FILES_PATTERN \
--files-from=$FILES_SRC \
/ $FULL_BACKUP_DIR
rm -f $BACKUP_DB_DIR/$DB_BACKUP_PREFIX\_$DAY\_*
nice -n 10 /usr/bin/mysqldump --complete-insert --all-databases --force --all --add-drop-table \
--host=$MYSQL_HOST \
--password=$MYSQL_PASSWD \
--user=$MYSQL_USER \
| gzip >$BACKUP_DB_DIR/$DB_BACKUP_PREFIX\_$DAY\_$TIMESTAMP.gz
nice -n 10 /usr/bin/mysqldump --complete-insert --all-databases --force --no-data --all --add-drop-table \
--host=$MYSQL_HOST \
--password=$MYSQL_PASSWD \
--user=$MYSQL_USER \
| gzip >$BACKUP_DB_DIR/$DB_BACKUP_PREFIX\_$DAY\_struct\_$TIMESTAMP.gz
rm -f $BACKUP_DB_DIR/$DB_BACKUP_PREFIX\_current*
ln -s $BACKUP_DB_DIR/$DB_BACKUP_PREFIX\_$DAY\_$TIMESTAMP.gz $BACKUP_DB_DIR/$DB_BACKUP_PREFIX\_current.gz
ln -s $BACKUP_DB_DIR/$DB_BACKUP_PREFIX\_$DAY\_struct\_$TIMESTAMP.gz $BACKUP_DB_DIR/$DB_BACKUP_PREFIX\_current\_struct.gz
rm -f $BACKUP_DIR/current\_*.tar.gz
cd $BACKUP_DIR
nice -n 10 tar -zcf $BACKUP_DIR/current\_$TIMESTAMP.tar.gz *