Dropbox Uploader database backups with deletion of older files on Dropbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
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
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?