-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusertarbal
executable file
·93 lines (90 loc) · 2.88 KB
/
usertarbal
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/local/bin/zsh
# Users Tarbal
STARTTIME=$(date +%s)
FileDate="${1:-$(date +%F)}"
Cloud="DropBox"
remoteDir="${Cloud}:/usertarbal"
localDir="usertarbal"
cloudDir="home/Cloud/${Cloud}/${localDir}"
cd /
[ ! -d /${localDir} ] && mkdir -p /${localDir}
[ ! -d /${localDir}/${FileDate} ] && mkdir -p /${localDir}/${FileDate}
check_error () {
local result=${1}
if [ ${result} -eq 0 ] || [ ${result} -eq 1 ]; then
printf "Done! (${result})\n"
else
printf "FAILED! (${result})\n"
r_errors=$((r_errors+1))
fi
}
backupNow () {
# Backup ${Dir} directory
local User=${1}
local Dir=${2}
printf "\n**** ${User} ****"
FileName="${User}-dir-${FileDate}.tgz"
rm -f /${localDir}/${FileDate}/${FileName} >/dev/null 2>&1
printf "\n **** Making \"${User}\" tarbal (/${localDir}/${FileDate}/${FileName})..."
tar -czf /${localDir}/${FileDate}/${FileName} -X /root/scripts/${User}-Exclude ${Dir}
results=$?
check_error ${results}
}
# Work starts here
if \ls "${HOME}/usertarbal\*.err" >/dev/null 2>&1; then
rm -f ${HOME}/usertarbal*.err > /dev/null 2>&1
fi
r_errors=0
for U D in root root y4x home/y4x elton home/elton mmost home/mmost tim home/tim randy home/randy joe home/joe ken home/ken linuxbrew home/linuxbrew
do
STARTTIME2=$(date +%s)
backupNow ${U} ${D}
Results="$(ls -1rtAhl /${localDir}/${FileDate}/${FileName}| awk '{print $5,$6,$7,$8,$9}')"
printf " ${Results}\n"
STOPTIME2=$(($(date +%s)-STARTTIME2))
STOPSTR2=" ** \"${U}\" Tarball Backup completed in"
show_time ${STOPTIME2} "${STOPSTR2}"
done
# Show number of t_errors during Backup transfer.
echo -e "\n**** Tarbals completed with ${r_errors} errors.\n"
# Move files to Dropbox
printf "**** Moving local tarbal files to ${remoteDir}/${FileDate}/..."
rclone moveto /${localDir}/${FileDate} ${remoteDir}/${FileDate} --cache-db-purge 2>/root/${localDir}${FileDate}.err
results=$?
if [ ${results} -eq 0 ] || [ ${results} -eq 1 ]; then
echo "Done."
else
echo "Errors."
fi
# Delete old backups
#
echo "**** Delete Old usertarbal Backups"
rbaseDir="DropBox:/usertarbal"
maxNrOfBackups=6
nrOfBackups=$(rclone lsf ${rbaseDir} --max-depth 1 | wc -l)
if [[ nrOfBackups -gt maxNrOfBackups ]]; then
echo " ** Removing old backups"
rclone lsf ${rbaseDir} --max-depth 1 | sort -r | tail -$(( nrOfBackups - maxNrOfBackups )) |
while read -r dirToRemove; do
printf "%s" " ** rclone purge ${rbaseDir}/${dirToRemove}..."
rclone purge ${rbaseDir}/${dirToRemove} --drive-use-trash=false
results=$?
if [[ results -eq 0 ]]; then
echo "Done."
rm -rf /${localDir}/${FileDate}
else
echo "Errors."
fi
done
# ~/bin/cleanfolder -m 6 -d -p /usertarbal
else
echo " ** No Old Backups to Delete"
fi
# Show time to do the transfer
STOPTIME=$(($(date +%s)-STARTTIME))
echo
show_time ${STOPTIME} "**** User Tarbal Backup Backups completed in"
echo
if [ ! -s ${HOME}/${localDir}${FileDate}.err ]; then
rm -f ${HOME}/${localDir}${FileDate}.err ] < /dev/null 2>&1
fi