-
Notifications
You must be signed in to change notification settings - Fork 0
/
Backup.sh
executable file
·53 lines (34 loc) · 993 Bytes
/
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
#!/bin/bash
is_file_older_than() {
seconds="$1"; file="$2";
if [[ ! -f "$file" ]]; then
return 1;
fi
modified_secs="$(date -r "$file" +%s)"
current_secs="$(date +%s)"
diff="$(expr "$current_secs" - "$modified_secs")"
if [[ "$diff" -gt "$seconds" ]]; then
rm "$file"
return 0
fi
return 1
}
echo Please enter directory path you want to backup.
read DIR_PATH
cd $DIR_PATH
tar -czvf $(date +"%F").tar.gz ./*
echo Please enter directory path that you want to put backup in it.
read BACKUP_DIR_PATH
mv ./*.tar.gz $BACKUP_DIR_PATH
cd $BACKUP_DIR_PATH
for i in ./*.tar.gz
do
is_file_older_than 604800 "$i";
done
# If you don't want to use telegram feature,simply comment below lines.
echo Please enter Telegram-Bot Token.
read $TOKEN
echo Please enter Chat-ID.
read $CHAT_ID
curl -F document=@"$BACKUP_DIR_PATH/*.tar.gz" \
"https://api.telegram.org/bot$TOKEN/sendDocument?chat_id=$CHAT_ID"