Friday 27 March 2015

Backing up an Owncloud Installation

Found THIS blog which explains how to backup OwnCloud with Rsnapshot which is a linux based backup solution that I love to use as it is really efficient and simple to install and configure.

The article is below:

After getting Owncloud up and running, I wanted to start making backups of the MySQL database and my custom configuration files. This ended up being easier than I thought. I found a good source describing the process here and also used the owncloud documentation. My basic plan is to use the rsnapshot tool to dump my MySQL database and backup my /var/www directory. In my installation, the Owncloud files are in the /var/www directory. A default installation would put those files in /var/www/owncloud, so make the appropriate adjustments if your installation is there.
First, I installed rsnapshot:
sudo apt-get update
sudo apt-get install rsnapshot
Then I set up a backup directory on the same 2TB USB drive that I have the data on.
sudo mkdir /media/owncloud/backups
sudo chmod 755 /media/owncloud/backups
sudo chown root:root /media/owncloud/backups
Next I set up rsnapshot config file. First, I copied the config file in case I messed it up:
sudo cp /etc/rsnapshot.conf /etc/rsnapshot.conf.old
Next I edited in the file. Note that this file requires tabs, not spaces, and you must have the trailing “/” on paths.
sudo nano /etc/rsnapshot.conf
First, I found the “SNAPSHOT ROOT DIRECTORY” section and change “snapshot_root” to path where the backups will be stored:
 ​snapshot_root /media/owncloud/backups/
Then I found the “BACKUP INTERVALS” section. I commented out all the retain lines except the “daily” by making sure “retain daily 7″ was uncommented.
I scrolled down to the entry for the logfile. I prefer to keep it in my log file directory:
 ​logfile /var/log/rsnapshot.log
Then I moved down to the “BACKUP POINTS / SCRIPTS” section. This is where you set up the backups. The first line backups the configuration (actually, the entire website except the data files stored on the USB drive). The second line dumps the MySQL database,
 # Owncloud – note: no data backup configured
#Backup Config
backup /var/www/ owncloud/
backup_script /usr/local/bin/backup_mysql.sh owncloud/database_dump
At this point, I saved and exited the rsnapshot config file and set up the MySQL script we added in the last step. First I moved the two required script files to /usr/local/bin/:
sudo ​cp /usr/share/doc/rsnapshot/examples/utils/backup_mysql.sh /usr/local/bin/
sudo cp /usr/share/doc/rsnapshot/examples/utils/mysqlbackup.pl /usr/local/bin/​
Then I set up the ownership and made them executable:
sudo chown root:root /usr/local/bin/backup_mysql.sh
sudo chown root:root /usr/local/bin/mysqlbackup.pl
sudo chmod 754 /usr/local/bin/backup_mysql.sh
sudo chmod 754 /usr/local/bin/mysqlbackup.pl​
Finally, I edited the script to only dump the Owncloud database.
sudo nano /usr/local/bin/backup_mysql.sh
I commented out the full backup and setup a backup of the owncloud database only. Make sure you use your owncloud database password.
 # backup Owncloud database and make readable only by root
/usr/bin/mysqldump -uowncloud -ppassword owncloud > owncloud_db.sql
/bin/chmod 600 owncloud_db.sql
That should configure everything. First thing I did was test that the config file didn’t have syntax errors:
sudo rsnapshot configtest
It came back with “Syntax OK”, so should be all set.
I ran the backup once, then checked the logs and backup directories to ensure it worked (it did!).
sudo rsnapshot daily
Finally, I automate with a crontab to run at 1:30am every morning.
sudo crontab -e
Then I added:
 30 01 * * * /usr/bin/rsnapshot daily​
Finally, here are the commands to restore the various parts of Owncloud:
Restore config:
rsync -avr --delete /media/owncloud/backups/daily.0/owncloud/var/www/config /var/www/
Restore apps:
rsync -avr --delete /media/owncloud/backups/daily.0/owncloud/var/www/apps /var/www/
Restore Themes:
rsync -avr --delete /media/owncloud/backups/daily.0/owncloud/var/www/themes /var/www/
Restore database:
​mysql -u owncloud -powncloud owncloud < /media/owncloud/backups/daily.0/owncloud/database_dump/owncloud_db.sql​

No comments:

Post a Comment