Restoring ownCloud
Introduction
Depending how the ownCloud instance has been installed, you may need slightly different steps to restore it from a backup.
In any case, you need the following components from your backup:
-
The
config/
directory. -
The
data/
directory.
Note that thedata/
directory may not only contain user files, but also keys for encryption. -
The
apps/
directory.
Note that this is only necessary if you are not using theapps-external/
directory and have added own apps or themes. -
The
apps-external/
directory.
Note that this is only necessary if it exists and is in use. -
The ownCloud database.
-
The custom theme files, if you had any. See Theming ownCloud.
Note that theme files are usually located in either theapps/
orapps-external/
directory.
If you have customized user home directories or a custom location for encryption keys, you have to manually take care of backing them up and restoring them to the same location. |
Prerequisites
To ensure a secure restore process, stop your web server to prevent users from accessing ownCloud via the web. As an alternative, you can stop serving the virtual host for ownCloud:
sudo service apache2 stop
Restore Scenarios
- Tarball Installation
-
-
If you have installed ownCloud from a tarball, you can safely restore the entire installation from the backup, with the exception of your ownCloud database. Databases cannot be copied, instead you must use the database tools to make a correct restoration.
-
You may also install a new instance from a tarball and restore the directories named above and the database. To avoid issues, use the same tarball version as the ownCloud version from the backup.
-
- Package Installation
-
If you have installed ownCloud from packages, start with a fresh ownCloud package installation in a new, empty directory. Then restore the above items from your Backup.
Only copy those files and folders from the apps/
backup directory which are NOT present after the installation. Do not overwrite items of theapps/
directory in the new installation. This will prevent a failing code integrity check and other errors.
After you have completed restoring files, see how to Set Correct Permissions.
Restore Directories
If possible, simply copy the directories from your backup to your new ownCloud environment, for example by running the following command from the backup directory. The following example command copies all directories mentioned above:
sudo rsync -Aax config data apps apps-external /var/www/owncloud/
There are many ways to restore normal files from backup. Use whatever method you are accustomed to.
Restore the Database
Before restoring the database, set your ownCloud instance into maintenance mode:
sudo -u www-data ./occ maintenance:mode --on
This guide assumes that your previous backup is called owncloud-dbbackup.bak , though the file may have a timestamp added in the filename.
|
Restoring Files From a Backup When Encryption Is Enabled
If you need to restore files from a backup during which encryption was enabled, proceed as follows with caution.
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:
|
-
Retrieve the encrypted flag value
-
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, thenumeric_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 the retrieved information, by running the following query, substituting the placeholders with the retrieved values:
UPDATE oc_filecache SET encrypted = <encrypted> WHERE fileid = <fileid>.
Final Tasks
Update ETag information
When a backup has been restored, the ETag information, which is necessary when accessing ownCloud with clients, has been changed. Run the following command to tell desktop and mobile clients that a server backup has been restored.
sudo -u www-data ./occ maintenance:data-fingerprint