-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackup-advanced.sh
executable file
·56 lines (41 loc) · 1.76 KB
/
backup-advanced.sh
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
55
56
#!/bin/bash
##########
# CONFIG #
##########
# MySQL login information
mysql_username=""
mysql_user_password=""
mysql_db_name=""
# Site address will be included in the file name of the backup, so
# basically it can be anything. This is just an identifier.
#site_address="example.com"
site_address=""
# Absolute path to the directory in which the backups will be stored.
# The path is defined without the trailing slash. See the example below:
#dir_for_backups="/home/user/backups"
dir_for_backups=""
# The absolute location of the files of the site to be backed up without
# the trailing slash. See the example below:
#dir_to_be_backed_up="/home/user/public_html"
dir_to_be_backed_up=""
#########
# LOGIC #
#########
# Create the backup directories if needed
[ ! -d ${dir_for_backups} ] && mkdir ${dir_for_backups}
[ ! -d ${dir_for_backups}/monthly ] && mkdir ${dir_for_backups}/monthly
[ ! -d ${dir_for_backups}/cyclic ] && mkdir ${dir_for_backups}/cyclic
mysqldump -u${mysql_username} -p${mysql_user_password} \
${mysql_db_name} | gzip > \
${dir_for_backups}/${site_address}_db_$(date +%y%m%d).sql.gz
tar cjf ${dir_for_backups}/${site_address}_files_$(date +%y%m%d).tbz \
--exclude ${dir_for_backups} \
${dir_to_be_backed_up}
if [ $(date +%d) = 01 ]; then
cp ${dir_for_backups}/${site_address}_db_$(date +%y%m%d)*.tbz \
${dir_for_backups}/monthly/
fi
mv ${dir_for_backups}/${site_address}_files_$(date +%y%m%d).tbz \
${dir_for_backups}/cyclic/${site_address}_files_$(date +%a).tbz
mv ${dir_for_backups}/${site_address}_db_$(date +%y%m%d).sql.gz \
${dir_for_backups}/cyclic/${site_address}_db_$(date +%a).sql.gz