-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestore_server.sh
executable file
·65 lines (56 loc) · 1.19 KB
/
restore_server.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
65
#!/bin/bash
# Include variables
. backups.conf
# Get the arguments
mode="$1"
backup="$2"
dest="$3"
function usage {
echo "Usage:"
echo "$0 files|db <backup_dir> <destination>"
echo ""
echo "For example:"
echo "$0 files /backups/daily.0/web root@newserver"
echo "$0 db /backups/weekly.0/db root@newserver"
exit 1
}
# Restore files
function restore_files {
# Warning
read -p "This will overwrite the server $dest. This action cannot be undone, are you sure? (yes/no) " input
if [ "${input,,}" != "yes" ]
then
exit 0
fi
# Zip the files up
cd "$backup"
tar -czf "$dest.tar.gz" .
# Copy file to the new server
rsync -a "$dest.tar.gz" $dest:/
ssh $dest "cd /; nohup tar zxf /$dest.tar.gz"
}
# Restore database
function restore_db {
# Warning
read -p "This will overwrite the server $dest. This action cannot be undone, are you sure? (yes/no) " input
if [ "${input,,}" != "yes" ]
then
exit 0
fi
# Copy over the sql file
rsync -a "$backup/var/db/dump/*.sql" $dest:/tmp/
read -p "MySQL password: " pass
ssh $dest "nohup mysql -uroot -p < /tmp/*.sql"
}
# Get the mode
case $mode in
"files")
restore_files
;;
"db")
restore_db
;;
*)
usage
;;
esac