Ken Robinson's picture

It is important to have a backup strategy in this hi-tech age. For loosing your data is like loosing your hard earned money! However even having a backup(s) (you should have more than one!), a backup is nothing without having restore plan and knowing that your backups work!. 

In this post I will walk you through my personal Mayan EDMS backup/restore strategy and other options as well that may work for you. Enough small talk, lets get this post started!

 


How I Use Mayan

My Mayan EDMS instance is used for my personal family documents. We scan any paper docs we get and hold them for a year then shred them unless we want a hard backup. I also have a test instance I use for testing new updates or things I want to test out before I make the changes in production. This test server is a copy of working production and I use the below backup/restore procedure to do this. I may in the future write a post about why having two environments is good practice at some point. 


I have used the scripts below to create a backup of my Mayan data, and in my case use this copy to restore to my test server so that I have copy of production. I use the restore script to restore the backup copy to the test server. However this is not my backup solution I use, however this is the bare minimum to get a backup copy of the data out of your Mayan server. 

I will have at the end of the post my actual backup solution if you want to know. But for right now here are the two scripts and commands that can be used to pull the data off of your Mayan server. I created these scripts based off the documentation on Mayans site

 

Backup Script

I use this script to dump the database and create a version and time stamped backup file of the media directory. 

#!/bin/bash
# Script to backup Mayan EDMS Data

# Put your installed Mayan version here! Make sure to update this if you
# update your version!
INSTALLED_MAYAN_VER=v4.4.1

echo "Backup Mayan Data on `date`"
echo ""

# Stop services
echo "Stopping Services..."
systemctl stop supervisor.service
echo ""
sleep 10
echo "Service Status"
systemctl --no-pager status supervisor.service
echo ""

# Dump database
echo "Remove old backup if there"
rm /opt/mayan-edms/media/mayan_db_backup_$INSTALLED_MAYAN_VER.sql
echo ""

echo "Dumping database to /opt/mayan-edms/media/mayan_db_backup_$INSTALLED_MAYAN_VER.sql"
pg_dump --dbname=mayan \
  --clean \
  --create \
  --format=plain \
  --file=/opt/mayan-edms/media/mayan_db_backup_$INSTALLED_MAYAN_VER.sql
echo ""

# Tar the media directory
TSTAMP=`date +%Y%m%d-%k%M%S`
echo "Tar/Zip Media Folder to ~/mayan-$INSTALLED_MAYAN_VER-backup_$TSTAMP.tar.gz /opt/mayan-edms/media/"
tar -zcvf ~/mayan-$INSTALLED_MAYAN_VER-backup_$TSTAMP.tar.gz /opt/mayan-edms/media/
echo ""

# Restart the services 
echo "Restarting Services"
systemctl start supervisor.service
echo ""
sleep 10
echo "Service Status"
systemctl --no-pager status supervisor.service
echo ""

echo "Backup script is complete on `date`"
echo ""

 

Restore Script


Once you have a backup its good to test it out. This is why I have a test server! I use the script below to restore my backup. This assumes that both the server the backup came from are on the same version!

 

#!/bin/bash
# Script to restore Mayan EDMS Data from backup file made from my backup
# script.

# Put your installed Mayan version here! Make sure to update this if you
# update your version!
INSTALLED_MAYAN_VER=v4.4.1

echo "Restore Mayan Data on `date`"
echo ""

# Stop services
echo "Stopping Services..."
systemctl stop supervisor.service
echo ""
sleep 10
echo "Service Status"
systemctl --no-pager status supervisor.service
echo ""

echo "Backup current database and media files"
# Dump database
echo "Remove old backup if there"
rm /opt/mayan-edms/media/mayan_db_backup_$INSTALLED_MAYAN_VER.sql
echo ""

echo "Dumping database to /opt/mayan-edms/media/mayan_db_backup_$INSTALLED_MAYAN_VER.sql"
pg_dump --dbname=mayan \
  --clean \
  --create \
  --format=plain \
  --file=/opt/mayan-edms/media/mayan_db_backup_$INSTALLED_MAYAN_VER.sql
echo ""

echo "Backup/Rename current media folder"
mv /opt/mayan-edms/media /opt/mayan-edms/media.backup
echo ""

# UnTar the backup file
echo "UnTar/Zip Media Folder from Backup file $1" 
tar -xzvf $1 -C /
echo ""

# Restore database
psql --set ON_ERROR_STOP=on --dbname=postgres \
     --file=/opt/mayan-edms/media/mayan_db_backup_$INSTALLED_MAYAN_VER.sql

# Restart the services 
echo "Restarting Services"
systemctl start supervisor.service
echo ""
sleep 10
echo "Service Status"
systemctl --no-pager status supervisor.service
echo ""

echo "Restore script is complete on `date`"
echo ""

 


How I Backup Mayan - Overkill

Just a side note, the way I backup Mayan is I have five copies of my Mayan server data. This could be consider overkill but try loosing all your data then paying $3000 USD to have most of it restored, you too will have a differnt outlook on your backups!

  • First copy is the working copy it's self. I use Proxmox so the server is virtual. This server has RAID10 ZFS storage to protect data in case of a drive or drive failures. 
  • My second copy is stored using Turnkey Linux Backup and Migration (TKLBAM) baked into every Turnkey app. This backups and can encrypt data to Amazon S3 buckets in the cloud. I use this as one of my offsite backups. 
  • The third copy of my data is in the form of snapshot four times a day of the virtual server to Proxmox Backup Server. The retention of these backups is as follows: Keep last seven snapshots, Keep one snapshot per day for the last fourteen days, Keep at least one per month for 12 months. This gives me really only one copy of my data but a time machine in case I need to go back many months. With Proxmox Backup you can do file based restores from your snapshots! The Proxmox Backup server also uses RAID10 ZFS to protect from drive failures and de-dups backup data so that only delta data is saved. This allows you to have many snapsots. Case in point, Currently I have 15TB of snapshots yet only using 22GB of storage! Thats a deduplication factor of 723! 
  • The fourth copy of my data is on tape. Proxmox Backup (I love Proxmox, it's open source too) can use tape backup systems and libraries. I happen to have gotten my hands on a IBM 9 Tape LTO6 system. Proxmox Backup works wonders with this and I can backup my snapshots/datastore to tape encrypted once a week. The tapes are stored on site in a fire proof safe.
  • The last copy of my data is a set of tapes I rotate out at my place of work. This is my second offsite copy of my data. 

Yeah thats a lot, but when you get burned I like I did... Well ya know.

 

Forum: 
Jeremy Davis's picture

You're such a legend Ken - thanks so much for sharing!

The thing that comes up from me after reading this though, is perhaps we could improve the TKLBAM setup for Mayan? My todo list is a bit overwhelming ATM, so I'm not sure when that might happen, but I'm sure we could improve the default TKLBAM backups.

Add new comment