Skip to content
This repository has been archived by the owner on Aug 6, 2022. It is now read-only.

II.4. Backups

Andrey Bogdanov edited this page Feb 24, 2016 · 4 revisions

It is a good practice to backup your server on a regular basis. rsync and cron combination is recommended. Below is an example backup configuration.

Server

First, you have to install cron and rsync, if they are not installed on your host.

Cron config

Then, you should configure cron (typically crontab -e), and enter something like:

30 4 * * 1 root cp /var/lib/redis/dump.rdb /path/to/ololord.js/backup

rsync config

uid = username
gid = username
read only = yes
list = yes
dont compress   = *.mp3 *.mpeg *.webm *.mp4 *.jpeg *.jpg *.png *.gif
use chroot = yes

[ololord.js]
        path = /path/to/ololord.js

Backup host

Cron config

0 5 * * 1 /path/to/backup-script.sh

backup-script.sh

#!/bin/bash
CURRENT_DATE=$( date +%Y-%m-%d-%H-%M ) # You may define your own format (use ``man date``)
REMOTE_USER=username # Your server user name
REMOTE_PASSWORD=password # Your server password
REMOTE_HOST=IP-address # Your server address
REMOTE_PATH=/path/to/ololord.js # The same as in the rsync config
LOCAL_PATH=/path/to/backups # Some local path
mkdir -p $LOCAL_PATH/logs && sshpass -p $REMOTE_PASSWORD rsync -av --exclude ".git" --delete $REMOTE_USER@$REMOTE_HOST:$REMOTE_PATH/ $LOCAL_PATH/latest >>$LOCAL_PATH/logs/$CURRENT_DATE.log 2>&1 && cp -r $LOCAL_PATH/latest $LOCAL_PATH/$CURRENT_DATE

Effect

Every monday at 04:30 AM the redis dump will be copied to the /path/to/ololord.js/backup server directory.

Then, at 05:00 AM the synchronization will be started.

Only new/modified files will be copied from the server to the backup host. Files deleted on the server will also be deleted on the backup host.

After synchronization is completed, the latest subdirectory on the backup host (where synchronization is done) will be copied to a directory with a specific time-based name.

Logs will be written to the logs subdirectory.

Important

Don't forget to set read permissions to files:

chmod +r file-name

and driectories:

chmod +rx dir-name