-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup-local.sh
More file actions
61 lines (43 loc) · 1.07 KB
/
backup-local.sh
File metadata and controls
61 lines (43 loc) · 1.07 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
#!/bin/bash
# local-backup.sh
# This script will create a backup on the local machine
# And it will support the commands backup and restore
#SOURCE="/etc/ /var/ /home/"
SOURCE="/root/Backup/demoDaten/ /etc/apache2/"
TARGET="/root/Backup/Backups/"
TIMESTAMP=$(date +%Y-%m-%d)
case "$1" in
backup)
echo "Backup started"
# Create directory if not already created
mkdir -p $TARGET -v
# Create backup
tar cvpzf $TARGET/backup_$TIMESTAMP.tar.gz $SOURCE
echo "Backup compleated"
;;
restore)
if [ -z "$2" ]; then
echo $"Usage: $0 restore <filename>"
exit 1
fi
restoreArchive="$TARGET$2"
if [ ! -f "$restoreArchive" ]; then
echo "Restore failed: File not found!"
echo $restoreArchive
exit 1
fi
echo "Restore backup"
tar xvpzf $restoreArchive -C /
echo "Restore completed"
;;
list)
echo "List of all available backups in $TARGET:"
find $TARGET -name "*tar.gz" -exec basename \{} \;
;;
help)
echo "This function is still in development!"
;;
*)
echo $"Usage: $0 {backup|restore|list|help}"
exit 1
esac