-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup_script.sh
executable file
·106 lines (75 loc) · 2.2 KB
/
backup_script.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
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/sh
#Log File
log_file="backup_log.txt"
#Fonction to log file
log_message(){
local timestamp
timestamp=$(date +"%Y-%m-%d %H:%M:%S")
echo "[$timestamp] $1" >> "log_file"
}
cat <<"EOF"
ad88888ba db 8b d8 88 ,ad8888ba, 88888888ba
d8" "8b d88b `8b d8' 88 d8"' `"8b 88 "8b
Y8, d8'`8b `8b d8' 88 d8' `8b 88 ,8P
`Y8aaaaa, d8' `8b `8b d8' 88 88 88 88aaaaaa8P'
`"""""8b, d8YaaaaY8b `8b d8' 88 88 88 88""""88'
`8b d8""""""""8b `8b d8' 88 Y8, ,8P 88 `8b
Y8a a8P d8' `8b `888' 88 Y8a. .a8P 88 `8b
"Y88888P" d8' `8b `8' 88 `"Y8888Y"' 88 `8b
By X3d1cu$
EOF
########### Backup Folder
backup_dir=backup
mkdir -p $backup_dir
########## Fonction for selecting files to be saved
select_files(){
echo "Select files to be saved separated by space please"
read -r files
}
######### Fonction for creating multiple backups
manage_backups(){
echo "Multiple backups program"
echo "1.Create a new backup"
echo "2.Backup list"
echo "3.Backup Restore"
read -p "Select a number" number
case $number in
1)
create_backup;;
2)
list_backups;;
3)
restore_backup;;
*)
echo "Invalid Option"
;;
esac
}
######## Fonction to create a new backup
create_backup(){
timestamp=$(date +"%Y%m%d%H%M%S")
backup_name="backup_$timestamp"
# Backup logging
log_message "Creating backup: $backup_name"
tar -cvf "$backup_dir/$backup_name.tar" $files
echo "Backup created with success: $backup_name"
# logging for successful backup
log_message "Backup created successfully: $backup_name"
}
######## Fonction to list backups
list_backups(){
echo "This is the backup list"
ls -lh $backup_dir
}
####### Fonction to restore backup
restore_backup(){
list_backups
read -r restore_name
tar -xvf "$backup_dir/$restore_name"
echo "Backup restored with success:$restore_name"
# Logging for sucessful restore
log_message "Backup restored successfully: $restore_name"
}
####### Main
select_files
manage_backups