forked from angelo-v/wordpress-backup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrestore
More file actions
executable file
·57 lines (45 loc) · 1.75 KB
/
restore
File metadata and controls
executable file
·57 lines (45 loc) · 1.75 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
#!/bin/bash
if ! [[ $1 ]]
then
echo "Error: Backup name missing"
echo "Please specify a backup name, e.g. 'restore 20141104'"
echo "Finished: FAILURE"
exit 0;
fi
if ! [[ $1 =~ ^[a-zA-Z0-9_-]+$ ]]
then
echo "The given backup name does not match the expected pattern: only characters, digits, underscore and dash are allowed ([a-zA-Z0-9_-])."
echo 'Finished: FAILURE'
exit 0
fi
FILES_ARCHIVE="/backups/backup_$1.tar.gz"
SQL_ARCHIVE="/backups/backup_$1.sql.bz2"
if [[ ! -f $FILES_ARCHIVE ]]
then
echo "The file $FILES_ARCHIVE does not exist. Aborting."
echo "Finished: FAILURE."
exit 0
fi
if [[ ! -f $SQL_ARCHIVE ]]
then
echo "The file $SQL_ARCHIVE does not exist. Aborting."
echo "Finished: FAILURE."
exit 0
fi
# cleanup html folder
echo "deleting files from /var/www/html/"
rm -R /var/www/html/*
# restore files
echo "restoring files from $FILES_ARCHIVE to /var/www/html"
tar -xzf $FILES_ARCHIVE --directory="/var/www/html/"
# update wp-config.php
sed -i s/"define('DB_NAME', '.*');"/"define('DB_NAME', '$MYSQL_ENV_MYSQL_DATABASE');"/g /var/www/html/wp-config.php
sed -i s/"define('DB_USER', '.*');"/"define('DB_USER', '$MYSQL_ENV_MYSQL_USER');"/g /var/www/html/wp-config.php
sed -i s/"define('DB_PASSWORD', '.*');"/"define('DB_PASSWORD', '$MYSQL_ENV_MYSQL_PASSWORD');"/g /var/www/html/wp-config.php
sed -i s/"define('DB_HOST', '.*');"/"define('DB_HOST', '$MYSQL_PORT_3306_TCP_ADDR:$MYSQL_PORT_3306_TCP_PORT');"/g /var/www/html/wp-config.php
# set correct file owner
chown -R www-data:www-data /var/www/html
# restore database
echo "restoring data from mysql dump file $SQL_ARCHIVE"
bunzip2 < $SQL_ARCHIVE | mysql -u$MYSQL_ENV_MYSQL_USER -p $MYSQL_ENV_MYSQL_DATABASE -p$MYSQL_ENV_MYSQL_PASSWORD -h $MYSQL_PORT_3306_TCP_ADDR
echo 'Finished: SUCCESS'