How to Automatically Back Up your ownCloud Data


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} ${OWNCLOUDDIR}data/;rm -r ${BACKUPDIR}${YESTERDAY}_*;

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

– Replace




– Replace


with the path to your ownCloud installation


– Replace


with the name of your ownCloud database.

– Replace


with the user assigned to your ownCloud database.

– Replace


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} ${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,



Tags: , , , , , , , , , , , , , , | Posted under 3rd Party Software | RSS 2.0

Author Spotlight

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.


Leave a Reply to Martin Cancel reply

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