I am running ownCloud on my Synology NAS for some months now and I am pretty happy how reliable it works. But if in some case my RAID would fail I’d loose all my private data. A periodic backup needed to be set up that backs up all my data in addition to the ownCloud configuration and database.
A bash script! What else? It somehow built up from a simple copy to a full fledged backup-split-dump-log bash script that I’d like to share with you. The full script is at the bottom of this page. I’d now like to talk about the parameters you should now to use this script on your installation.
What it does
The script simply backs up all you ownCloud data and configuration so that you could make a fresh install in case of a total failure.
- Makes a database dump and copies it to the backup destination
- Archives, splits and copies the ownCloud data in 1GB files to the backup destination
- Copies the ownCloud configuration dir to the backup destination
This script should work with every installation of ownCloud using a MySQL database. I am running it on my Synology now but it was running on an Ubuntu Server for a year now successfully. Additionally you need a MySQL user that has SELECT and LOCK TABLES permissions on the owncloud database.
All user dependant parameters are located on the top of the script. They are:
|DRY_RUN||Set to 1 to make a dry run without writing anything or 0 for normal mode|
|DELETE_OLDEST_BACKUP||Set to 1 to delete the oldest backup on the destination before this backup starts.|
|LOG_FILE||Log file location|
|DEFAULT_DEST||Default backup detination if none is passed to the script|
|OCC_LOCATION||Location of the owncloud command line tool|
|OC_LOCATION||owncloud Installation directory|
|OC_WEB_USR||Web user to run occ|
|SOURCE||Owncloud data location|
|DB_USR||Database user, needs SELECT and LOCK TABLE access on DB_NAME|
|DB_PW||Database user password|
|DB_NAME||owncloud database name|
I am running the script through Task Scheduler once a week.
- Control Panel -> Task Scheduler
- Create -> Scheduled Task -> User-defined Script
- Task: ocbackup User: root This is very important
- Task Settings User-defined Script: Location of the ocbackup.sh file
Also available here: https://gist.github.com/noah95/9cd484c894ae629963c00a1ef973e8f9