-
Notifications
You must be signed in to change notification settings - Fork 6
/
dropbox_auto_backup_cron.sh
45 lines (28 loc) · 1.15 KB
/
dropbox_auto_backup_cron.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
#!/bin/bash
#Save current date as YYYY-MM-DD to a variable
DATE=$(date +"%Y-%m-%d")
BACKUP_FOLDER="/home/backup/"
#Loop through each file in the backup folder whose name has the current date
for X in "$BACKUP_FOLDER"*$DATE*; do
#if file not found dont continue
if [ ! -e $X ]
then
exit
fi
#X is the filename with path. Remove path to get just the filename.
NAME_NO_PATH=${X##*/}
#Remove the date from the name (removes all text between the periods)
NEW_NAME="${NAME_NO_PATH%%.*}.${NAME_NO_PATH##*.}"
#get username
USER_NAME="${NAME_NO_PATH%%.*}"
#Copy the file to tmp with the new non-dated name
cp $X "$BACKUP_FOLDER$NEW_NAME"
#Send it to Dropbox (using downloaded api dropbox_uploader.sh)
/dropbox/dropbox_uploader.sh -f /root/.dropbox_uploader upload "$BACKUP_FOLDER$NEW_NAME" /
#delete uploaded data
rm -rf "$BACKUP_FOLDER$NEW_NAME"
#fixing the problem that will exist
export VESTA=/usr/local/vesta/
#Delete the backup using api (so the counter is updated in panel)
sudo /usr/local/vesta/bin/v-delete-user-backup $USER_NAME $NAME_NO_PATH
done