OwnCloud does a fine job listing the steps for creating backups and updating an ownCloud server. Read all about it here. I’m not going to copy ownCloud’s information here. I’ll give some sample scripts you can use targeted at the specific lab setup we created in the previous parts of this series.
Backup up ownCloud
As per ownCloud’s suggestions below script backs up the config folder, the data folder and the database. In addition it lists all installed packages; this list can serve as a base to quickly reinstall them should you need to reinstall your server.
This script backs up to a Windows server. It assumes you have installed smbclient and /root/.smbcreds contains the Windows server share’s credentials in this format:
The file should only be readable by root:
# chmod 600 /root/.smbcreds
The script creates daily folders containing full backups. I suggest you keep a bunch of recent ones and some older ones, or back up the config and data separately in order to not completely fill up your drives in a week.
The backups are stored in the share \\server01\backups in a folder called “ownCloud daily backups” to demonstrate how to handle paths with spaces.
Create a file called /root/backup.sh:
#! /bin/bash NOW=$(date +"%Y-%m-%d") # Create backupdir mkdir ./$NOW # Write list of installed packages to backupdir dpkg --get-selections | grep -v deinstall > ./$NOW/InstalledPackages.txt # Copy software config to backup dir cp -R /etc/ ./$NOW # Copy ownCloud install and config to backup dir cp -R /var/www/owncloud ./$NOW # Copy ownCloud data to backup dir cp -R /var/ownclouddata ./$NOW # Export Mysql database and copy to backup dir mysqldump -uroot --password=Y0urSqLp4ssw0rd --events --all-databases > ./$NOW/mysqlbackup.sql # Copy backupdir to tarball tar -cvpzf backup-$NOW.tar.gz ./$NOW # Copy tarball to backup server smbclient //server01/backups -l 192.168.1.2 -A /root/.smbcreds -c "cd \"ownCloud daily backups\"; put backup-$NOW.tar.gz backup-$NOW.tar.gz" # Remove backupdir and tarball rm -R /root/$NOW rm /root/backup-$NOW.tar.gz
Make the script executable:
# chmod +x /root/backup.sh
Configure the script to run every night using cron:
# crontab -e
Add this line:
59 0 * * * bash /root/backup.sh
Check your backups regularly.
Of course if you’re running ownCloud on a VM you could just create exports and save those on your server.
- Install Debian
- Setup the correct repositories
- Reinstall all software with the selections list from your backup:
# dpkg --set-selections < selections # apt-get update && apt-get -u dselect-upgrade
- Install ownCloud including a database with the same name as before
- Import the database backup to the fresh one:
# mysql -u root -p --one-database owncloud < mysqlbackup.sql
- Restore the data from your backup.
OwnCloud extensively covers upgrading on their site.
The only thing I want to add is you may want to create a snapshot of your server before upgrading.
I compliment ownCloud on their ongoing professional and technical growth. And I know it’s not a favourite activity of a lot of people but ownCloud really improved their documentation in the last couple of years. I hope they will continue on this path.