Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Dropbox Uploader database backups with deletion of older files on Dropbox
# Dropbox Config
# Database Credentials
# Other options
backup_path="" # full path to backup dir
user_path="" # full path to current user's home dir
date=$(date +"%Y-%m-%d_%H%M%S")
# Set default file perms
umask 177
# Dump DB file
mysqldump --user=$dbuser --password=$dbpass $dbname > $backup_path/$dbname-$date.sql
# Upload the file to Dropbox
# Requires [Dropbox Uploader](
dropbox_uploader -f $user_path/$dropboxconfig upload $backup_path/$dbname-$date.sql /$dbname-$date.sql
# Delete .sql files older than 5 days
find $backup_path/*.sql -mtime +5 -exec rm {} \;
# Remove old Dropbox backups
cd $backup_path
backups=($(find *.sql)) # Array of current backups
dropboxfiles=($(dropbox_uploader -f $user_path/$dropboxconfig list / | awk 'NR!=1{ print $3 }')) # Array of Dropbox files
in_array() {
local hay needle=$1
for hay; do
[[ $hay == $needle ]] && return 0
return 1
for i in "${dropboxfiles[@]}"
in_array $i "${backups[@]}" && echo 'Keeping ' $i || dropbox_uploader -f $user_path/$dropboxconfig delete /$i
Copy link

Hello this is exellent script, but i have one problem. On the last stage of the script trying to delete old dropbox files, i get:
"Deleting "/backup-2017-09-12_143059.sql.gz"... FAILED"
"Deleting "/backup-2017-04-12_123047.sql.g"... FAILED"
"Deleting "/backup-2017-02-12_113032.sql.g"... FAILED"

Why the script failing to delete old files?

Copy link

duceduc commented Oct 27, 2019

Hi there. I have found your script to delete files older than xx days in dropbox using the dropbox_uploader script, but I cannot get it to delete files in drop. I have modify your script to download backup zip files. The script uploads the files to dropbox, but it doesn't delete old files in dropbox. No errors or any line that says it is deleting....... When you have the time, can you take a look at the code? Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment