-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBackup_duplicacy.sh
69 lines (59 loc) · 2.55 KB
/
Backup_duplicacy.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
#!/usr/bin/env bash
######################### Parameters ##########################################
snapshot_id="archive"
repository="/data/lab"
storage="/archive/lab_duplicacy"
uploading_threads=16
broadcast="TRUE"
###############################################################################
duplicacy &>/dev/null
[ $? -eq 127 ] && {
echo -e "Cannot find the command duplicacy.\n"
exit 1
}
if [[ ! -d $repository ]]; then
echo -e "ERROR! Cannot find the repository directory (the directory to be backed up): $repository"
exit 1
fi
if [[ ! -d $storage ]]; then
echo -e "ERROR! Cannot find the storage directory (the directory used to store data): $storage"
exit 1
fi
cd $repository
duplicacy check &>/dev/null
if [[ $? != 0 ]]; then
echo -e "ERROR! duplicacy check failed. Please make sure repository or storage has been initialized."
echo -e "One can use the command to initialize: \ncd $repository; rm -rf $repository/.duplicacy;duplicacy init $snapshot_id $storage"
exit 1
fi
####### Start preocessing #######
logfile=$storage/AllBackup.log
SECONDS=0
echo -e "****************** Start Backup ******************" &>>$logfile
echo -e ">>> Backup start at $(date +'%Y-%m-%d %H:%M:%S')" &>>$logfile
echo -e ">>> Backup repository: ${repository}" &>>$logfile
echo -e ">>> Backup storage: ${storage}\n" &>>$logfile
echo -e "*** Make a duplicacy backup for the repository" &>>$logfile
tag="bk_$(date +"%Y-%m-%d-%H.%M.%S")"
cmd="duplicacy backup -storage $storage -threads $uploading_threads -t \"$tag\" "
echo -e "*** Run duplicacy command: \n$cmd" &>>$logfile
#echo "$cmd"
eval $cmd &>>$logfile
if [[ $? != 0 ]]; then
echo -e "Backup failed!\n" &>>$logfile
ELAPSED="Elapsed: $(($SECONDS / 3600))hrs $((($SECONDS / 60) % 60))min $(($SECONDS % 60))sec"
echo -e "$ELAPSED" &>>$logfile
echo -e "****************** Backup failed ******************\n\n\n" &>>$logfile
if [[ $broadcast == "TRUE" ]]; then
echo -e ">>> $(date +'%Y-%m-%d %H:%M:%S') Backup_duplicacy(${repository}): Backup failed! Please check the log: $storage/AllBackup.log" >>/etc/motd
fi
exit 1
else
echo -e "Backup completed.\n" &>>$logfile
ELAPSED="Elapsed: $(($SECONDS / 3600))hrs $((($SECONDS / 60) % 60))min $(($SECONDS % 60))sec"
echo -e "$ELAPSED" &>>$logfile
echo -e "****************** Backup completed successfully ******************\n\n\n" &>>$logfile
if [[ $broadcast == "TRUE" ]]; then
echo -e ">>> $(date +'%Y-%m-%d %H:%M:%S') Backup_duplicacy(${repository}): Backup completed successfully! Snapshot: $tag" >>/etc/motd
fi
fi