Backing up ownCloud
When you backup your ownCloud server, there are four things that you need to copy:
-
Your
config/
directory. -
Your
data/
directory. -
Your ownCloud database.
-
Your custom theme files, if you have any. (See Theming ownCloud)
When you install your ownCloud server from our
Open
Build Service packages (or from distro packages, which we do not
recommend) do not backup your ownCloud server files, which are the
other files in your owncloud/
directory such as core/
, 3rdparty/
,
apps/
, lib/
, and all the rest of the ownCloud files. If you restore
these files from backup they may not be in sync with the current package
versions, and will fail the code integrity check. This may also cause
other errors, such as white pages.
When you install ownCloud from the source tarballs this will not be an issue, and you can safely backup your entire ownCloud installation, with the exception of your ownCloud database. Databases cannot be copied, but you must use the database tools to make a correct database dump.
To restore your ownCloud installation from backup, see Restoring ownCloud.
Backing Up the config/ and data/ Directories
Simply copy your config/
and data/
folder to a place outside of your
ownCloud environment. This example uses rsync
to copy the two
directories to /oc-backupdir
:
rsync -Aax config data /oc-backupdir/
There are many ways to backup normal files, and you may use whatever method you are accustomed to.
Backup Database
You can’t just copy a database, but must use the database tools to make a correct database dump.
MySQL/MariaDB
MySQL or MariaDB, which is a drop-in MySQL replacement, is the recommended database engine. To backup MySQL/MariaDB:
mysqldump --single-transaction -h [server] -u [username] -p [password] [db_name] > owncloud-dbbackup_`date +"%Y%m%d"`.bak
Example:
mysqldump --single-transaction -h localhost -u username -p password owncloud > owncloud-dbbackup_`date +"%Y%m%d"`.bak
Restoring Files From Backup When Encryption Is Enabled
If you need to restore files from backup, which were backed up when encryption was enabled, here’s how to do it.
This is not officially supported. ownCloud officially supports either restoring the full backup or restoring nothing — not restoring individual parts of it. |
-
Restore the file from backup.
-
Restore the file’s encryption keys from your backup.
-
Run
occ files:scan
, which makes the scanner find it.
In the DB it will:
|
-
Update the encrypted flag.
There’s no need to update the encrypted flag for files in either files_versions or files_trashbin ,
because these aren’t scanned or found by occ files:scan .
|
-
Download the file once as the user; the file’s size will be corrected automatically.
This process might not be suitable across all environments. If it’s not suitable for yours, you might need to run an OCC command that does the scanning.
Retrieve the Encrypted Flag Value
-
In the backup database, retrieve the
numeric_id
value for the storage where the file was located from theoc_storages
table and store the value for later reference. For example, if you have the following in youroc_storages
table, thennumeric_id
you should use is3
, if you need to restore a file foruser1
.+--------------------------------+------------+-----------+--------------+ | id | numeric_id | available | last_checked | +--------------------------------+------------+-----------+--------------+ | home::admin | 1 | 1 | NULL | | local::/var/www/owncloud/data/ | 2 | 1 | NULL | | home::user1 | 3 | 1 | NULL | +--------------------------------+------------+-----------+--------------+
-
In the live database instance, find the
fileid
of the file to restore by running the query below, substituting the placeholders for the retrieved values, and store the value for later reference.SELECT fileid FROM oc_filecache WHERE path = 'path/to/the/file/to/restore' AND storage = <numeric_id>
-
Retrieve the backup, which includes the data folder and database.
-
Retrieve the required file from your backup and copy it to the real instance.
-
In the backup database, retrieve the file’s
encrypted
value, by running the query below and store the value for later reference. The example query assumes the storage was the same and the file was in the same location. If not, you will need to track down where the file was before.SELECT encrypted FROM oc_filecache WHERE path = 'path/to/the/file/to/restore' AND storage = <numeric_id>
-
Update the live database instance with retrieved information, by running the following query, substituting the placeholders for the retrieved values:
UPDATE oc_filecache SET encrypted = <encrypted> WHERE fileid = <fileid>.