Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Daniel Werner
Daniel Werner

Posted on • Originally published atdanielwerner.dev on

     

Automated linux server backup with Dropbox

Introduction

I was looking around for some low cost backup solution for my server when I got an idea. Let’s use dropbox for that. The free version of dropbox has 2 GB of space and it has an official linux client. The offered space is not too much, but for smaller sites it is good enough.

I’ve created a collection ofscripts for the backup, it creates the backup of the given input directory, from the Nginx configurations and all databases. The backup is stored in the synchronized Dropbox directory the last 30 files are kept, the older ones are automatically deleted. Let’s see how to use it.

Set up the scripts

Create a dropbox user

sudo adduser --disabled-password dropbox
Enter fullscreen modeExit fullscreen mode

Install Dropbox

sudo su dropbox cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86\_64" | tar xzf -
Enter fullscreen modeExit fullscreen mode

Start the dropbox daemon and open the link displayed by the daemon to link to your dropbox account with your server. For more information about installing dropbox for linux please visit the Dropbox’s official instructionshere.

~/.dropbox-dist/dropboxd
Enter fullscreen modeExit fullscreen mode

Install thebackmeup scripts into the home directory of the Dropbox user:

cd /home/dropboxgit clone https://github.com/daniel-werner/backmeup.git
Enter fullscreen modeExit fullscreen mode

Add dropbox daemon to crontab to start it automatically after reboot

crontab -e
Enter fullscreen modeExit fullscreen mode

Insert the following line

@reboot ~/.dropbox-dist/dropboxd
Enter fullscreen modeExit fullscreen mode

Add the backup script to run every day at 1:00 AM, replace the input directory and the database login credentials

0 1 * * * sh /home/dropbox/backmeup/bin/backup.sh -i /var/www/vhosts -o /home/dropbox/Dropbox/backup -u backup -p secret
Enter fullscreen modeExit fullscreen mode

I’d recommend creating a new mysql user for the backup with the following global privileges: select, references, create view, show view, execute, lock tables.

That’s it, you just need to either manually start the dropbox daemon in background or restart the server to have the cron job start it.

How it works

If you are still reading and interested in details let’s take a look at the scripts:

backmeup/bin/backup.sh

This script is responsible for creating the backup of the files and calling the database backup script. It accepts the following arguments:

-u the mysql username to use for the database backup

-p the password for mysql

-i the input directory for the backup

-o output directory where the backup will be placed

The backup file contains the following directory structure:

configs – contains the backup of nginx sites configuration (/etc/nginx/sites-available)

databases – all the mysql databases are dumped to separate gzipped files and placed in this directory

sites – the backup of the input directory

backmeup/bin/dump-all-databases.sh

This script creates backup of all databases into separate files. The output can be plain text dump or gzipped. It accepts the following arguments:

-u mysql username

-p mysql password

-o output directory

-z use gzip output: if this argument is present the output file will be gzipped

The source code is available on GitHub, please find ithere. If you have any comment or suggestion please share it in comments.

The postAutomated linux server backup with Dropbox appeared first onDaniel Werner.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Senior Software Developer.Clean Code and TDD enthusiast. Team lead and mentor.
  • Location
    Subotica, Serbia
  • Joined

More fromDaniel Werner

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp