-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup.sh
More file actions
executable file
·65 lines (48 loc) · 1.36 KB
/
backup.sh
File metadata and controls
executable file
·65 lines (48 loc) · 1.36 KB
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
65
#!/bin/bash
#### Initial variables ####
# Max of backups to keep
max_days=3
# root direcroty for backup
dir=$PWD
# file name prefix
prefix="backup"
now=$(date +"%d%m%Y")
old=$(date --date="${max_days} days ago" +"%d%m%Y")
oldsqlfile="${prefix}_mysql_${old}.sql.gz"
newsqlfile="${prefix}_mysql_${now}.sql.gz"
oldwebfile="${prefix}_web_${old}.tar"
newwebfile="${prefix}_web_${now}.tar"
oldsqlfilepath="${dir}/backup/mysql/${oldsqlfile}"
newsqlfilepath="${dir}/backup/mysql/${newsqlfile}"
oldwebfilepath="${dir}/backup/web/${oldwebfile}"
newwebfilepath="${dir}/backup/web/${newwebfile}"
if [ ! -d $dir/backup/mysql/ ]; then
mkdir -p $dir/backup/mysql/
fi
if [ ! -d $dir/backup/web/ ]; then
mkdir -p $dir/backup/web/
fi
if [ -f $oldsqlfilepath ];
then
rm $oldsqlfilepath
echo "Deleted $oldsqlfilepath"
fi
if [ -f $oldwebfilepath ];
then
rm $oldwebfilepath
echo "Deleted $oldwebfilepath"
fi
if [ -f $newsqlfilepath ];
then
echo "Last database backup file already exists"
else
docker exec wp-database sh -c 'exec mysqldump -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" ${MYSQL_DATABASE}' | gzip -9 > $newsqlfilepath
echo "Created $newsqlfilepath"
fi
if [ -f $newwebfilepath ];
then
echo "Last web backup file already exists"
else
tar -cf $newwebfilepath --exclude-from=$dir"/backup-exclude.txt" -C $dir wordpress
echo "Created $newwebfilepath"
fi