forked from erkkimon/backup-advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
/
restore-advanced.sh
executable file
·52 lines (37 loc) · 1.33 KB
/
restore-advanced.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
#!/bin/bash
##########
# CONFIG #
##########
# MySQL login information
mysql_username="root"
mysql_user_password=#"" #password here
mysql_db_name="techshareroom_wiki"
#Folder variables and files
database_file="techshareroom_wiki_db_2021-12-24_00-00-01.sql.gz"
database_file_uncompressed="techshareroom_wiki_db_2021-12-24_00-00-01.sql"
dir_file="techshareroom_wiki_files_2021-12-24_00-00-06.tbz"
dir_for_backups="/home/usuario/backups/techshareroom_wiki"
dir_to_be_backed_up="/var/www/html/techshareroom_wiki"
#########
# LOGIC #
#########
echo "Restoring the wiki! Data & DB. Please be patient..."
#1º Move to backup directory
cd ${dir_for_backups}
#2º Execute a file + db backup of actual status
./backup-advanced.sh
#3º Drop actual database
mysqladmin -u${mysql_username} -p${mysql_user_password} drop ${mysql_db_name}
#4º Remove actual folder
rm -rf ${dir_to_be_backed_up}
#5º Create the new db
mysqladmin -u${mysql_username} -p${mysql_user_password} create ${mysql_db_name}
#6º Uncompress db file
gzip -d ${database_file}
#7º Import db dump inside the new db
echo "Dumping database, please wait"
mysql -u${mysql_username} -p${mysql_user_password} ${mysql_db_name} < ${dir_for_backups}/${database_file_uncompressed}
#8º Uncompress files on the correct folder
tar xvjf ${dir_file} -C /var --strip-components=1
echo
echo "All operationes DONE"