Skip to content

Commit 052bdc1

Browse files
authored
Update docker_backup.sh
As per Grahams suggestion added grep command to check if any old backup files exist on dropbox before issuing the delete command. This remove the error if less than 7 backup files exist.
1 parent d1996e4 commit 052bdc1

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

scripts/docker_backup.sh

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ if [ -f ./backups/dropbox ]; then
6161

6262
#list older files to be deleted from cloud (exludes last 7)
6363
#to change dropbox backups retained, change below -7 to whatever you want
64-
echo "getting older filenames to be deleted from dropbox"
64+
echo "checking for old backups on dropbox"
6565
files=$($dropboxuploader list $dropboxfolder | awk {' print $3 '} | tail -n +2 | head -n -7)
6666

6767
#write files to be deleted to dropbox logfile
@@ -70,15 +70,18 @@ if [ -f ./backups/dropbox ]; then
7070
echo $files | tr " " "\n" >$dropboxlog
7171

7272
#delete files from dropbox as per logfile
73-
echo "deleting files from dropbox - last 7 files are kept"
74-
echo "if less than 7 files are in dropbox you wil see FAILED message below"
75-
input=$dropboxlog
76-
while IFS= read -r file
77-
do
78-
$dropboxuploader delete $dropboxfolder/$file
79-
done < "$input"
73+
echo "deleting old backups from dropbox if they exist - last 7 files are kept"
8074

81-
echo "deleted from dropbox" >>$dropboxlog
75+
#check older files exist on dropbox, if yes then delete them
76+
if [ $( echo "$files" | grep -c "backup") -ne 0 ] ; then
77+
input=$dropboxlog
78+
while IFS= read -r file
79+
do
80+
$dropboxuploader delete $dropboxfolder/$file
81+
done < "$input"
82+
fi
83+
84+
echo "backups deleted from dropbox" >>$dropboxlog
8285

8386
fi
8487

@@ -93,5 +96,4 @@ if [ -f ./backups/rclone ]; then
9396
fi
9497

9598

96-
9799
popd

0 commit comments

Comments
 (0)