-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackupScript.sh
More file actions
105 lines (96 loc) · 3.73 KB
/
BackupScript.sh
File metadata and controls
105 lines (96 loc) · 3.73 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
echo "-------------------------------------------------------------"
echo " ____ _ _____ ____ ____ ____ ____ _ _ _____"
echo "/ _\/ \ / __//_ \ / _\/ _ \/ _ \/ \/ \ /|/ __/"
echo "| / | | | \ / / | / | / \|| | \|| || |\ ||| | _"
echo "| \_ | |_/\| /_ / /___| \_ | \_/|| |_/|| || | \||| |_//"
echo "\____/\____/\____\\____/\/\____/\____/\____/\_/\_/ \|\____\ "
echo " "
echo "-------------------------------------------------------------"
echo "$(tput setaf 1) This is my Backup Script.Your Backups are located in /opt/Backup/!
This Script ONLY makes a Backup of your files.
You have to download this backup via WinSCP or FileZilla after the script is finished"$(tput sgr0)
mkdir -p /opt/Backup/{Webserver,Home,Backup-Other,SQLBackup}
PS3='Please choose an Option: '
options=("Webserver" "Home" "Backup What You Want" "MQSQL Backup" "Import MQSQL Backup" "Import Webserver Backup" "Import Any Backup" "Quit")
select opt in "${options[@]}"
do
case $opt in
"Webserver")
DATE=$(date +%Y-%m-%d-%H-%M-%-S)
BACKUP_DIR="/opt/Backup/Webserver"
SOURCE="/var/www/html"
tar -cvzpf $BACKUP_DIR/backup-$DATE.tar.gz $SOURCE
echo "Thanks for using my script."
exit
;;
"Home")
DATE=$(date +%Y-%m-%d-%H-%M-%-S)
BACKUP_DIR="/opt/Backup/Home"
SOURCE="/home"
tar -cvzpf $BACKUP_DIR/backup-$DATE.tar.gz $SOURCE
echo "Thanks for using my script."
exit
;;
"Backup What You Want")
read -p "Please enter the directory you want to backup: " dir
read -p "Please enter a name for the backup: " name
DATE=$(date +%Y-%m-%d-%H-%M-%-S)
BACKUP_DIR="/opt/Backup/Backup-Other"
cd $dir
tar cfvz $name-$DATE.tar.gz * && mv $name-$DATE.tar.gz /opt/Backup/Backup-Other/
echo "Thanks for using my script."
exit
;;
"MQSQL Backup")
read -p "Please enter your MQSQL admin username: " user
read -p "Please enter your MQSQL admin password: " password
read -p "Please enter the MQSQL database you want to backup: " database
DATE=$(date +%Y-%m-%d-%H-%M-%-S)
BACKUP_DIR="/opt/SQLBackup"
mysqldump --no-tablespaces --host=localhost --user=$user --password=$password $database > $database-$DATE.sql
mv $database-$DATE.sql /opt/Backup/SQLBackup/
echo "Thanks for using my script."
exit
;;
"Import MQSQL Backup")
read -p "Please enter your MQSQL admin username: " user
read -p "Please enter your MQSQL admin password: " password
read -p "Please enter the name for the new MQSQL database " database
mysql -e "CREATE DATABASE '$database';"
read -p "Please enter the name of the Backup you want to import(Please the full file name without .sql!! " databasename
mysql --host=localhost --user=$user --password=$password $database < $databasename.sql
echo "Thanks for using my script."
exit
;;
"Import Webserver Backup")
read -p "Enter the filename of your Backup File without the .zip: " filename
cd /var/www/html/test
tar -xvzf $filename
echo "Thanks for using my script."
exit
;;
"Import Home Backup")
read -p "Enter the filename of your Backup File without the .zip: " filename
cd /var/www/html/test/web
tar -xvzf $filename
echo "Thanks for using my script."
exit
;;
"Import Any Backup")
cd /opt
cp -r * /root
read -p "Enter the directory where the Backup is located:" backuplocation
cd $backuplocation
read -p "Enter the filename of your Backup File with the file type(.tar.gz) " filename
read -p "Enter the directory with slashes where you want to import your Backup: " dir
mv $filename $dir/
cd $dir
tar -xvzf $filename
echo "Thanks for using my script."
exit
;;
"Quit")
exit
esac
done