Difference between revisions of "Backup Procedures"

Step by step how-to instructions on installing and running KoBo Toolbox on a standalone server.
Jump to: navigation, search
m
m
 
Line 2: Line 2:
 
* [[Kobo Docker Setup#Automatic backup creation|KoBo backup creation]] enabled
 
* [[Kobo Docker Setup#Automatic backup creation|KoBo backup creation]] enabled
 
* [[Backup Setup|Backup setup]] completed
 
* [[Backup Setup|Backup setup]] completed
$ sudo nano /usr/sbin/kobo-backup
 
<blockquote><pre>
 
#!/bin/bash
 
KOBO_DOCKER=/home/ate/kobo-docker
 
KEEP_DAYS=31
 
LOCAL=/srv/kobo-backups/
 
REMOTE=/media/kobo-backups/kobo-backups/
 
  
function log {
+
Backup archives are created in <code>$KOBO_DOCKER/backups/</code> folder, each [[Backup_Targets_and_Storage#Targets|backup target]] in a separate sub-directory: postgres, mongo and kobocat.
        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
 
fi
 
  
log "MSF KoBo Toolbox backup script starting"
+
== kobo-backup script ==
cd $KOBO_DOCKER
+
From the point of creation, backup archives are <b>moved</b> to the local destination <code>/srv/kobo-backups</code>; sub-directory structure is not retained. KoBo Toolbox backup creation mechanism just creates files, deleting nothing. Appropriate method of backup rotation has to be implemented outside KoBo, and in this case it starts with moving.
  
log "Postgres backup..."
+
Local destination is searched for archives older than 31 days, which are removed.
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..."
+
Local destination is then <code>rsync</code>-ed to remote <code>/media/kobo-backups/kobo-backups</code>. We do not <code>rsync</code> directly to <code>/media/kobo-backups</code> because <code>rsync</code> requires full control over destinatkion, so the Windows share itself will not do; but a sub-directory will.
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...."
+
Finally, email notifications are dispatched.
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..."
+
== Automatic backups ==
rsync --archive --delete  $LOCAL $REMOTE
 
log "rsync done"
 
log "MSF KoBo Toolbox backup script completed"
 
touch /root/kobo-last-backup.timestamp
 
  
echo "---"
+
== Manual backups ==
echo "automated message sent by KoBo Toolbox backup * support@mreznisistemi.rs *"
 
</pre></blockquote>
 
$ sudo chown root:root /usr/sbin/kobo-backup
 
$ sudo chmod 0755 /usr/sbin/kobo-backup
 
  
$ sudo nano /etc/cron.d/kobo-backup
+
Backup scripts can be started manually, in which case notifications are displayed rather than emailed.
<blockquote><pre>
 
MAILTO=root
 
SHELL=/bin/bash
 
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 
  
30 3 * * *  root    kobo-backup
+
$ cd $KOBO_DOCKER
</pre></blockquote>
+
$ sudo docker exec -it kobodocker_kobocat_1 /srv/src/kobocat/docker/backup_media.bash
 +
$ sudo docker exec -it kobodocker_mongo_1 /srv/backup_mongo.bash
 +
$ sudo docker exec -it kobodocker_postgres_1 /srv/backup_postgres.bash
 +
$ sudo /usr/sbin/kobo-backup

Latest revision as of 14:03, 5 January 2017

Pre-requisites:

Backup archives are created in $KOBO_DOCKER/backups/ folder, each backup target in a separate sub-directory: postgres, mongo and kobocat.

kobo-backup script

From the point of creation, backup archives are moved to the local destination /srv/kobo-backups; sub-directory structure is not retained. KoBo Toolbox backup creation mechanism just creates files, deleting nothing. Appropriate method of backup rotation has to be implemented outside KoBo, and in this case it starts with moving.

Local destination is searched for archives older than 31 days, which are removed.

Local destination is then rsync-ed to remote /media/kobo-backups/kobo-backups. We do not rsync directly to /media/kobo-backups because rsync requires full control over destinatkion, so the Windows share itself will not do; but a sub-directory will.

Finally, email notifications are dispatched.

Automatic backups

Manual backups

Backup scripts can be started manually, in which case notifications are displayed rather than emailed.

$ cd $KOBO_DOCKER
$ sudo docker exec -it kobodocker_kobocat_1 /srv/src/kobocat/docker/backup_media.bash
$ sudo docker exec -it kobodocker_mongo_1 /srv/backup_mongo.bash
$ sudo docker exec -it kobodocker_postgres_1 /srv/backup_postgres.bash
$ sudo /usr/sbin/kobo-backup