Simple Dropbox daily backups

Find an article
Jun 11
Published by in with 1 Comment
( words)
Warning! There was an error loading some of the images for this post.

One of the most annoying things about administering a system is when it fails and you have no backup. A simple but effective method of mitigating this risk is to backup to a remote storage facility. Services such as Dropbox / Google Drive ensure that your data is safe and secure. In this tutorial I cover how to set-up a simple backup script to cover the most important files on your system:

Download the Dropbox uploader script:

cd /usr/local/sbin/

Give execution permissions to the script and run it:

chmod +x

Create the backup wrapper script using a text editor of your choosing:

# Copyright 2014 Kieran Brahney <>
SERVER_NAME="SERVER-1" # Name of the server to identify backups

DROPBOX_EXE="/usr/local/sbin/" # location of dropbox uploader
DROPBOX_DIR="" # where you want to save it in your Dropbox account

BACKUP_SRC="/var/www /home /etc /root" # anything else you can think of that is a critical setting file for you

MYSQL_USER="" # best to use the root account for this
MYSQL_PASS="" # Your msql password
MYSQL_EXCL="information_schema" # exclude these DBs from the backup (separated by | no spaces)
FTP_SERVER="" # Remote FTP server to backup
FTP_USER="" # best to use root for this
FTP_PASS="" # your ftp password
# Stop editing here.
NOW="Backup-$SERVER_NAME-"$(date +"%Y.%m.%d")
# Backup MySQL (if set)
if [ $MYSQL_USER ]; then
        # Pull the DB
        mysql -h$MYSQL_SERVER -N -e "show databases like '%';" |
                grep -v -E "$MYSQL_EXCL" |
                xargs mysqldump -h$MYSQL_SERVER --databases |
                bzip2 -c > "$BACKUP_DST/$NOW-Databases.sql.bz2"
        # Append to backup file list
        BACKUP_FILES="$BACKUP_FILES $BACKUP_DST/$NOW-Databases.sql.bz2"

# Backup Remote FTP server (if set)
if [ $FTP_USER ]; then
        # Url encode to escape any special chars e.g. @ symbols
        FTP_USER="$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$FTP_USER")"
        FTP_PASS="$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$FTP_PASS")"
        # Create dir for files
        mkdir -p "$BACKUP_DST/FTP_BACKUP"
        # Pull remote FTP files
        wget -q -P "$BACKUP_DST/FTP_BACKUP" -m ftp://$FTP_USER:$FTP_PASS\@$FTP_SERVER
        # Append to backup file list
# Compress all of the backup files
# Upload to dropbox
# Clean up
rm -rf "$DESTFILE" "$BACKUP_DST/$NOW-Databases.sql.bz2" "$BACKUP_DST/FTP_BACKUP"
(find /tmp/du_* -mtime +1 -exec rm {} \;) >& /dev/null # Delete files older than a day
# Check for older backups
while read -r state size file rest
    if [[ $state = "[F]" && $file = "Backup-$SERVER_NAME-"* ]]
        if [[ $file != "$NOW.tgz" ]]
                $DROPBOX_EXE delete "$file"
done < <($DROPBOX_EXE list /)

Configure the options at the top of the file. If you’re not interested in MySQL or FTP backups you can simply ignore these.

Create a nightly backup:

crontab -e
0 23 * * * /usr/local/sbin/dropbox_backup



How do I stop receiving: “Warning: Using a password on the command line interface can be insecure.”
Create ~/.my.cnf and input your username and password in the below format:



1 Comment

Leave a Reply to Mike Mattas Cancel reply

Your email address will not be published.