Skip to content

Instantly share code, notes, and snippets.

@mwender
Last active October 27, 2019 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwender/6b17f9927d40e37c1dbf to your computer and use it in GitHub Desktop.
Save mwender/6b17f9927d40e37c1dbf to your computer and use it in GitHub Desktop.
Dropbox Uploader database backups with deletion of older files on Dropbox
#!/bin/bash
# Dropbox Config
dropboxconfig=".dropbox_uploader"
# Database Credentials
dbuser=""
dbpass=""
dbname=""
# 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](https://github.com/andreafabrizi/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
shift
for hay; do
[[ $hay == $needle ]] && return 0
done
return 1
}
for i in "${dropboxfiles[@]}"
do
in_array $i "${backups[@]}" && echo 'Keeping ' $i || dropbox_uploader -f $user_path/$dropboxconfig delete /$i
done
@duceduc
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.

http://dl.ducsu.com/on/dbWs1.sh

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