- Restore Scenarios
- Restore the Database
- Restoring Files From a Backup When Encryption Is Enabled
- Final Tasks
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:
Note that the
data/directory may not only contain user files, but also keys for encryption.
Note that this is only necessary if you are not using the
apps-external/directory and have added own apps or themes.
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 the
|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.|
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
- 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 the
apps/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.
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.
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
Depending on the database version and the setup, username and password may not be necessary. To restore MySQL/MariaDB:
sudo mysql -h [server] -u [username] -p[password] [db_name] < owncloud-dbbackup.bak
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.
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
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.
In the backup database, retrieve the
numeric_idvalue for the storage where the file was located from the
oc_storagestable and store the value for later reference. For example, if you have the following in your
numeric_idyou should use is
3if you need to restore a file for
+--------------------------------+------------+-----------+--------------+ | 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
fileidof 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
encryptedvalue 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>.
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
Start your web server, or alternatively enable the virtual host serving ownCloud:
sudo service apache2 start