How to Automatically Back Up your ownCloud Data

Hello,

For the ones using ownCloud as their personal cloud solution, you may have found that you have important files stored there that you ought to back up regularly in case you somehow lose them. Today I’ll show you how to automatically keep a backup of your files by using Cron Jobs. Works for any ownCloud version.

1. Identify the path of your ownCloud installation. For this article, it will be /home/user/public_html/cloud/

2. Create the directory where your backups will be saved. I recommend creating it outside the public scope, not inside your public_html, because we don’t want others to see them, right? This time I’ll have it at /home/user/owncloud_backups/ – you can create it either via cPanel’s File Manager, FTP or SSH.

3. Log into your cPanel.

4. Go to Cron Jobs.

5. We will add the following Cron Job that will execute at 3AM daily (you can change the hour to what you prefer, of course), that will back up your ownCloud database, zip your data and remove the day before’s backups:

BACKUPDIR=**/home/user/owncloud_backups/**;OWNCLOUDDIR=**/home/user/public_html/cloud/**;TODAY=`date +"%Y%m%d"`;YESTERDAY=`date --date=‘-1 day' +"%Y%m%d"`;mysqldump --lock-tables --databases **user_ownclouddb** -h localhost -u **user_ownclouduser** -p**DBpassword** > ${BACKUPDIR}${TODAY}_owncloud_database.bak;zip -r ${BACKUPDIR}${TODAY}_owncloud_data.zip ${OWNCLOUDDIR}data/;rm -r ${BACKUPDIR}${YESTERDAY}_*;

We will need to edit what is between double stars (**…**). 

– Replace

**/home/user/owncloud_backups/**

with

/home/(YOURUSERNAME)/owncloud_backups/

– Replace

**/home/user/public_html/cloud/**

with the path to your ownCloud installation

/home/(YOURUSERNAME)/public_html/cloud/

– Replace

**user_ownclouddb**

with the name of your ownCloud database.

– Replace

**user_ownclouduser**

with the user assigned to your ownCloud database.

– Replace

**DBUserPassword**

with your database assigned user’s password.

-> To make your Cron run daily at 3AM, you must set it as 0 3 * * *

Now in case it wasn’t clear at all how you the cron job should be edited, check the following:

ownCloud directory: /home/arvixe/public_html/owncloud/
Backup directory: /home/arvixe/owncloud_backups/
DB Name: arvixe_ownclouddb
DB User: arvixe_ownclouduser
DB Pass: tes83nd0sj20

upon that details, our Cron Job should like this:

BACKUPDIR=/home/arvixe/owncloud_backups/;OWNCLOUDDIR=/home/arvixe/public_html/owncloud/;TODAY=`date +"%Y%m%d"`;YESTERDAY=`date --date=‘-1 day' +"%Y%m%d"`;mysqldump --lock-tables --databases arvixe_ownclouddb -h localhost -u arvixe_ownclouduser -ptes83nd0sj20 > ${BACKUPDIR}${TODAY}_owncloud_database.bak;zip -r ${BACKUPDIR}${TODAY}_owncloud_data.zip ${OWNCLOUDDIR}data/;rm -r ${BACKUPDIR}${YESTERDAY}_*;

And there you go. Your backups will be stored at /home/youruser/owncloud_backups . Please let me know if you have any questions or get stuck at any step. I’ll be more than happy to assist you troubleshooting your issue.

Best Regards,

Richi

References:
http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html
http://doc.owncloud.org/server/6.0/admin_manual/maintenance/backup.html
Tags: , , , , , , , , , , , , , , | Posted under 3rd Party Software | RSS 2.0

Author Spotlight

Richi González

Richi González

I started programming when I was 12. I'm a Developer and have been working with the Clip-Bucket script since it came out. I'm the Liaison between Arvixe and Clip-Bucket, so anything you need regarding Clip-Bucket or any particular computer-related subject you need, let me know so I can assist you.

2 Comments on How to Automatically Back Up your ownCloud Data

  1. Martin says:

    Hello Richi, a really useful guide. Thank you very much. It would be great if you could add two more features to the cron job:

    1. Instead of removing yesterdays backup keep all backups for a couple of weeks.
    2. Copy the backup files to an external folder e.g. a FTP Server.

    Cheers,
    Martin

Leave a Reply

Your email address will not be published. Required fields are marked *


9 − 7 =

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>