Part 1: Introduction
Part 2: Installing Debian 8
Part 3: Installing ownCloud 8
Part 4: Connecting to Active Directory
Part 5: Security
Part 6: Miscellany
Part 7: Server maintenance
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:
[code]username=vorkbaard
password=P@55w0rd[/code]
The file should only be readable by root:
[code]
# chmod 600 /root/.smbcreds
[/code]
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:
[code]
#! /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
[/code]
Make the script executable:
[code]
# chmod +x /root/backup.sh
[/code]
Configure the script to run every night using cron:
[code]
# crontab -e
[/code]
Add this line:
[code]
59 0 * * * bash /root/backup.sh
[/code]
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.
Restoring ownCloud
To restore your backup to a fresh installation first completely setup the server:
- Install Debian
- Setup the correct repositories
- Reinstall all software with the selections list from your backup:
[code]
# dpkg –set-selections < selections
# apt-get update && apt-get -u dselect-upgrade
[/code] - Install ownCloud including a database with the same name as before
- Import the database backup to the fresh one:
[code]# mysql -u root -p –one-database owncloud < mysqlbackup.sql[/code] - Restore the data from your backup.
Updating ownCloud
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.