-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbackup.sh
66 lines (53 loc) · 1.02 KB
/
backup.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
#!/bin/bash
FOLDERS_TO_SAVE=("config" "guilds" "log" "resources")
if [ $# -eq 0 ]
then
echo "Missing argument"
exit 1
fi
BACKUP_PATH=$(realpath $1)
WD=$(pwd)
if [ ! -d "$BACKUP_PATH" ]
then
echo "The given folder doesn't exist"
exit 1
fi
echo "Backup destination: $BACKUP_PATH"
if [ ! -d "$BACKUP_PATH/temp" ]
then
mkdir "$BACKUP_PATH/temp"
if [ $? -eq 0 ]
then
echo "$BACKUP_PATH/temp folder create"
else
echo "Error during the creation of the folder $BACKUP_PATH/temp"
exit 1
fi
fi
echo "Start backup"
for folder in ${FOLDERS_TO_SAVE[@]}
do
echo " - $folder"
cp -r "$folder" "$BACKUP_PATH/temp/$folder"
if [ $? -ne 0 ]
then
echo "Error during the backup"
exit 1
fi
done
echo "Backup end"
echo "Zip backup..."
NOW=$(date +"%H-%M-%d-%m-%y")
ZIP_NAME="$BACKUP_PATH/backup_palilabot_$NOW.zip"
echo "Backup filename : $ZIP_NAME"
cd "$BACKUP_PATH/temp"
zip -qr "$ZIP_NAME" *
if [ $? -ne 0 ]
then
echo "Error during the creation of the zip file"
exit 1
fi
cd "$WD"
rm -r "$BACKUP_PATH/temp"
echo "Done"
exit 0