Backup Setup

Step by step how-to instructions on installing and running KoBo Toolbox on a standalone server.
Revision as of 10:03, 5 January 2017 by Vladimir (talk | contribs) (2. Create mounting point and add entry to Host's fstab)

Jump to: navigation, search

Permanently mount backup storage onto KoBo server's filesystem

Create the file containing cretendials for Windows share, and restrict access to the file

$ sudo nano /etc/samba/kobo-backups.cred
$ sudo chmod 0600 /etc/samba/kobo-backups.cred

Create mounting point and add entry to Host's fstab

$ sudo mkdir /media/kobo-backups
$ sudo nano /etc/fstab

...adding the following two lines at the end of the file. The second line starts with // and contains everything upto the end.

# KOBO-Backups folder on
// /media/kobo-backups cifs credentials=/etc/samba/kobo-backups.cred,iocharset=utf8,sec=ntlm 0 0

The backup share will this be automatically mounted on every reboot of the system. To activate the changes immediately, issue the command

$ sudo umount -a

Backup script

$ sudo nano /usr/sbin/kobo-backup

function log {
        echo  "`date +'[%d/%b/%Y:%k:%M:%S %z]'` $1"
if [[ $UID != 0 ]]; then
    echo "Please run this script as root:"
    echo "sudo $0 $*"
    exit 1

log "MSF KoBo Toolbox backup script starting"

log "Postgres backup..."
docker exec kobodocker_postgres_1 bash -c "pg_dump --format=c --no-privileges --no-owner kobotoolbox -U postgres > /srv/db/backup/current.pgdump"
mv --verbose $KOBO_DOCKER/.vols/db/backup/current.pgdump $KOBO_DOCKER/backups/postgres/`date +%Y%m%d%H%M`.pgdump
log "postgres done"

log "Moving files..."
touch -t `date +%m%d0000` /tmp/$$
find $KOBO_DOCKER/backups/ -type f -newer /tmp/$$ -exec mv --verbose -f {} $LOCAL \;
rm /tmp/$$
log "mv done"

log "Remove archives older than $KEEP_DAYS days..."
find $LOCAL -type f -mtime +$KEEP_DAYS \( -name "*.tar" -o -name "*.tar.gz" -o -name "*.pgdump" -o -name "*.pgrestore" \) -exec rm --verbose {} \;
log "unlink done"

log "RSyncing local and remote backup destination..."
rsync --archive --delete  $LOCAL $REMOTE
log "rsync done"
log "MSF KoBo Toolbox backup script completed"
touch /root/kobo-last-backup.timestamp

echo "---"
echo "automated message sent by KoBo Toolbox backup * *"
$ sudo chown root:root /usr/sbin/kobo-backup
$ sudo chmod 0755 /usr/sbin/kobo-backup

Schedule backup execution

$ sudo nano /etc/cron.d/kobo-backup 

30 3 * * *   root    kobo-backup