forked from databacker/mysql-backup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup_wordpress_root.sh
executable file
·49 lines (40 loc) · 1.44 KB
/
backup_wordpress_root.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
#!/bin/bash
# Backup a WordPress site (db + files).
WWW_ROOT=${WWW_ROOT:-"/var/www/html/wp-content"}
SERVICE_NAME=${SERVICE_NAME:-"wordpress"}
EXCLUDE_FILE=${EXCLUDE_FILE:-"${WWW_ROOT}/wp-content/.mysql-backup_excludes"}
if [[ -n "$DB_DUMP_DEBUG" ]]; then
set -x
fi
if [ -e ${EXCLUDE_FILE} ]; then
exclude_files=" -X ${EXCLUDE_FILE}"
fi
NOW=$(date +"%Y-%m-%d-%H_%M")
if [ -e ${DUMPFILE} ];
then
backups_dir=$(dirname ${DUMPFILE})
tmp_dir=$(mktemp -d)
wordpress_files="${SERVICE_NAME}-${NOW}-files.tar.gz"
wordpress_full_backup="${SERVICE_NAME}-${NOW}-full.tar.gz"
restore_dir="/restore"
mkdir ${restore_dir}
echo "Backing up ${WWW_ROOT} directory"
cd /${tmp_dir}
tar zcf ${wordpress_files} -C ${tmp_dir} ${WWW_ROOT} ${exclude_files}
[[ $? -gt 0 ]] && echo "Could not compress files from ${SERVICE_NAME} directory!" && exit 1
echo "Copying SQL dump file"
cp ${DUMPFILE} ${tmp_dir}
[[ $? -gt 0 ]] && echo "Could not copy SQL dump!" && exit 1
echo "Creating new tarball"
#cd ${restore_dir}
tar zcf ${restore_dir}/${wordpress_full_backup} *
[[ $? -gt 0 ]] && echo "Could not create ${SERVICE_NAME} full backup file!" && exit 1
echo "Moving new backup file to: ${DUMPDIR}"
mv ${restore_dir}/${wordpress_full_backup} ${DUMPDIR}
[[ $? -gt 0 ]] && echo "Could not move the backup file to ${DUMPDIR}!" && exit 1
#cleanup
rm -fr ${tmp_dir}
rm -fr ${DUMPFILE}
else
echo "ERROR: Backup file ${DUMPFILE} does not exist!"
fi