-
Notifications
You must be signed in to change notification settings - Fork 4
II.4. Backups
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.
First, you have to install cron
and rsync
, if they are not installed on your host.
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
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
0 5 * * 1 /path/to/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
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.
Don't forget to set read
permissions to files:
chmod +r file-name
and driectories:
chmod +rx dir-name