bin bash MYSQL_USER user MYSQL_PASSWORD password GPG_PASSWORD gpg_pass

 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
#!/bin/bash
MYSQL_USER="user"
MYSQL_PASSWORD="password"
GPG_PASSWORD="gpg_password"
BACKUP_DIRECTORY="/home/backups"
databases=`mysql --user=$MYSQL_USER --password=$MYSQL_PASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
curr_date=`date +%Y\.%m\.%d`
for db in $databases; do
echo `date +%H:%M:%S` ": Dumping database: $db"
OPT=""
if [[ "$db" == "mysql" ]] ; then
OPT=" --events"
fi
mysqldump --user=$MYSQL_USER --password=$MYSQL_PASSWORD --databases $db --add-drop-table --add-locks --create-options --single-transaction -Q -c -e $OPT > /tmp/$curr_date.$db.sql
done
echo `date +%H:%M:%S` ": Create DB archive"
cd /tmp
tar czf /home/db_`date +%Y%m%d`.tgz *.sql
echo `date +%H:%M:%S` ": Remove tmp sql files"
rm /tmp/*.sql
echo `date +%H:%M:%S` ": Backup etc files"
cd /etc/
tar czf /home/etc_`date +%Y%m%d`.tgz *
echo `date +%H:%M:%S` ": Backup root files"
cd /root/
tar czf /home/root_`date +%Y%m%d`.tgz *
echo `date +%H:%M:%S` ": Backup all files"
cd /home/
tar czf $BACKUP_DIRECTORY/backup_`date +%Y%m%d`.tgz * --exclude="backups" --exclude="*/wp-content/cache/*"
/usr/bin/gpg -c --force-mdc --batch --yes --passphrase==$GPG_PASSWORD BACKUP_DIRECTORY/backup_`date +%Y%m%d`.tgz
echo `date +%H:%M:%S` ": Remove tmp files"
rm /home/db_`date +%Y%m%d`.tgz /home/etc_`date +%Y%m%d`.tgz /home/root_`date +%Y%m%d`.tgz BACKUP_DIRECTORY/backup_`date +%Y%m%d`.tgz
echo `date +%H:%M:%S` ": Remove old backup files"
echo `date +%H:%M:%S` ": Yandex.Disk sync"
/usr/bin/yandex-disk sync