Storing Backups in Dropbox
Learn how to securely store backups in Dropbox using the backup-manager script. This guide covers installation, configuration, and automation steps.
Storing Backups in Dropbox
There are several relevant sayings and proverbs about the necessity of creating backups. Regardless of whether the data is hosted on a dedicated server or VDS, it is essential to set up backups not only locally but also on a separate server or network storage.
In cases where a control panel is used (ISPManager, Vesta or other similar solutions), backup functions can often be implemented with the help of the panel itself. However, we will consider the scenario where no panel is used on the server or for some reasons backups must be made in another way. In our example, we will implement the following scheme — creating backups of directories with websites and uploading them to Dropbox.
Preparing Archives with Backup-Manager
For preparing archives, we will use backup-manager — a simple script available in the repositories of popular operating systems. Installation is done using the standard package manager:
# CentOS
yum install backup-manager
# Debian, Ubuntu
apt-get install backup-manager
After installation, we will edit the file /etc/backup-manager.conf using your favorite text editor. The configuration file is quite well documented; we will adjust it to the following format:
export BM_DAILY_CRON="true" # daily execution
export BM_REPOSITORY_ROOT="/var/backup-manager" # backup storage directory
export BM_TEMP_DIR="/var/tmp" # temporary directory
export BM_REPOSITORY_SECURE="true"
export BM_REPOSITORY_USER="root"
export BM_REPOSITORY_GROUP="root"
export BM_REPOSITORY_CHMOD="770"
export BM_ARCHIVE_CHMOD="660"
export BM_ARCHIVE_TTL="5"
export BM_ARCHIVE_FREQUENCY="daily"
export BM_REPOSITORY_RECURSIVEPURGE="false"
export BM_ARCHIVE_PURGEDUPS="true"
export BM_ARCHIVE_PREFIX="$HOSTNAME"
export BM_ARCHIVE_STRICTPURGE="true"
export BM_ARCHIVE_NICE_LEVEL="10"
export BM_ARCHIVE_METHOD="tarball-incremental mysql" # file copies and MySQL dumps
export BM_TARBALL_NAMEFORMAT="long"
export BM_TARBALL_FILETYPE="tar.gz"
export BM_TARBALL_DUMPSYMLINKS="false"
declare -a BM_TARBALL_TARGETS # below we specify the necessary directories
BM_TARBALL_TARGETS[0]="/etc"
BM_TARBALL_TARGETS[1]="/var/www"
BM_TARBALL_TARGETS[2]="/home"
BM_TARBALL_TARGETS[3]="/root"
export BM_TARBALL_TARGETS
export BM_TARBALLINC_MASTERDATETYPE="weekly"
export BM_TARBALLINC_MASTERDATEVALUE="1"
export BM_MYSQL_DATABASES="__ALL__"
export BM_MYSQL_SAFEDUMPS="true"
export BM_MYSQL_ADMINLOGIN="root"
export BM_MYSQL_ADMINPASS="SeCuRePaSsWoRd" # MySQL password
export BM_MYSQL_HOST="localhost"
export BM_MYSQL_PORT="3306"
export BM_MYSQL_FILETYPE="bzip2"
Now we can check that the backup-manager successfully creates data archives. Let’s run it from the command line and check the results:
# backup-manager -v
/var/backup-manager/server.itldc.com-etc.20140416.master.tar.gz: ok (9M, 80933e817bf70aa079ddb7515698e25e)
/var/backup-manager/server.itldc.com-var-www.20140416.master.tar.gz: ok (1M, 0aae02715773e09298f7fd26e3d0a7f7)
/var/backup-manager/server.itldc.com-home.20140416.master.tar.gz: ok (1M, 0b11cc7e8cecc36e9004b5bd223a963d)
/var/backup-manager/server.itldc.com-root.20140416.master.tar.gz: ok (48M, 9147e1817894295015d7438e8ea28678)
Creating a default MySQL client configuration file: /root/.backup-manager_my.cnf
/var/backup-manager/server.itldc.com-all-mysql-databases.20140416.sql.bz2: ok (1M, 93cee49736e67c71001825b31606a86d)
# ls -l /var/backup-manager/
total 56512
-rw-rw---- 1 root root 396 Apr 16 14:20 server.itldc.com-20140416.md5
-rw-rw---- 1 root root 101758 Apr 16 14:20 server.itldc.com-all-mysql-databases.20140416.sql.bz2
-rw-rw---- 1 root root 8733029 Apr 16 14:20 server.itldc.com-etc.20140416.master.tar.gz
-rw------- 1 root root 30605 Apr 16 14:20 server.itldc.com-etc.incremental.bin
-rw-rw---- 1 root root 467 Apr 16 14:20 server.itldc.com-home.20140416.master.tar.gz
-rw------- 1 root root 179 Apr 16 14:20 server.itldc.com-home.incremental.bin
-rw-rw---- 1 root root 48862421 Apr 16 14:20 server.itldc.com-root.20140416.master.tar.gz
-rw------- 1 root root 5825 Apr 16 14:20 server.itldc.com-root.incremental.bin
-rw-rw---- 1 root root 102889 Apr 16 14:20 server.itldc.com-var-www.20140416.master.tar.gz
-rw------- 1 root root 3668 Apr 16 14:20 server.itldc.com-var-www.incremental.bin
Great, the backups have been created, and from now on, backup-manager will run every night — since we set BM_DAILY_CRON="true" in its configuration. Let’s move on to the next step — uploading our archives to Dropbox.
Uploading Backups to Dropbox
We recommend creating a separate Dropbox account for storing backups. Once registration is complete, download and install the official Dropbox client on our server:
wget -O - "http://www.dropbox.com/download/?plat=lnx.x86_64" | tar xvzf - -C /root
After that, we need to authorize our server to start working with Dropbox. Let’s run the client script:
# /root/.dropbox-dist/dropbox
This computer is not connected to a Dropbox account...
To connect this computer, go to https://www.dropbox.com/cli_link?host_id=XXXXXXXXXXXXXXXXXXXXXXXXXXXX.
Copy the link provided into your clipboard and open it in your browser. If necessary, log in to the Dropbox website. Immediately afterward, the script will inform you about the successful association of your server with your Dropbox account:
This computer is now connected to the Dropbox account. Welcome, Test User!
Press Ctrl-C and proceed to configure the Dropbox client. To start with, ensure that dropboxd starts on system boot. This can be done most easily with the scheduler — launching crontab -uroot -e and adding the following line:
@reboot $HOME/.dropbox-dist/dropboxd
Next, create a symbolic link to inform the Dropbox client about the location of the backup files:
ln -s /var/backup-manager /root/Dropbox/backup
The configuration is complete. Let’s restart the server or run the Dropbox client:
/root/.dropbox-dist/dropbox &
At this point, the configuration of our backup system is complete. Within a few minutes, the backups of our data will be uploaded to cloud storage, and they will be accessible at any time. Every day, backup-manager will create an updated archive of files and databases, while the Dropbox client will ensure their upload to cloud storage.
Need Help?
Our support team is available 24/7 to assist you with any questions or issues.
Contact Support