-
Notifications
You must be signed in to change notification settings - Fork 2
/
backup_script.sh
64 lines (45 loc) · 1.67 KB
/
backup_script.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
57
58
59
60
61
62
63
64
#!/bin/bash
# XenForo backup script
# Made by James because I hate doing this manually
#### CONFIG - YOU MUST EDIT THIS ####
# set database connection info
db_username="username"
db_password="password"
db_name="database"
# set compression method (pigz, pbzip2 or standard gzip)
compression_method="pigz"
# set path to backups and website directory without trailing slashes:
# your backup location
backup_path="/path/to/backup/directory"
# your web root location
web_dir="/path/to/website/directory"
# set amazon S3 bucket and directory (leave blank to disable AWS uploading)
bucket_name=""
#### END CONFIG - YOU PROBABLY DONT NEED TO EDIT BELOW HERE ####
# set filenames
if [ "$compression_method" == "pbzip2" ]; then
extension="bz2"
else
extension="gz"
fi
filename_sql="backup-db-$(eval date +%Y%m%d).sql"
filename_sql_gz="backup-db-$(eval date +%Y%m%d).$extension"
filename_data="backup-data-folder.tar"
filename_data_gz="backup-data-folder.tar.$extension"
# dump the database
mysqldump -u$db_username -p$db_password $db_name > "$backup_path/$filename_sql"
# compress the database
$compression_method -9 -f "$backup_path/$filename_sql"
# create a tarball of the web folder
tar -cf "$backup_path/$filename_data" "$web_dir/"
# move the old one to _old
mv "$backup_path/$filename_data_gz" "$backup_path/old_$filename_data_gz"
# compress the website directory
$compression_method -9 -f "$backup_path/$filename_data"
# has user set a bucket name?
if [ -n "$bucket_name" ]; then
# upload to Amazon S3...
s3put $bucket_name "$backup_path/$filename_sql_gz"
fi
# write to the backup log
echo "Backup for $(eval date +%d)/$(eval date +%m)/$(eval date +%Y) complete" >> $backup_path/backup.log