-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwpbackup
executable file
·33 lines (24 loc) · 971 Bytes
/
wpbackup
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
#!/bin/bash
echo "starting backup..."
while getopts "u:h:f:" flag
do
case "$flag" in
u) user=${OPTARG};;
h) host=${OPTARG};;
f) folder=${OPTARG};;
esac
done
stamp=$( date '+%Y-%m-%d_%H%M' )
wp_path=$( ssh ${user}@${host} wp find ${folder} --field='wp_path' ) &&
# if wp find isn't available
# wp_path="/home/${user}/${folder}" &&
ssh ${user}@${host} wp maintenance-mode activate --path=${wp_path} &&
echo "archiving files..." &&
ssh ${user}@${host} tar czvf - ${folder} > backup_${stamp}_${folder}.tar.gz &&
echo "files archived successfully" &&
echo "exporting database..." &&
ssh ${user}@${host} wp db export --path=${wp_path} - | gzip > backup_${stamp}_${folder}-db.sql.gz &&
echo "database exported successfully" &&
ssh ${user}@${host} wp maintenance-mode deactivate --path=${wp_path} &&
echo "compressed file archive: ${PWD}/backup_${stamp}_${folder}.tar.gz" &&
echo "compressed database export: ${PWD}/backup_${stamp}_${folder}-db.sql.gz"