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 data of the Docker volume mount point (<mount-point>) which includes the
apps,configand thefilesfolder
For details see the Mount Folder Structure documentation. -
The ownCloud database.
-
The custom theme files, if you had any. See Theming ownCloud.
Note that theme files are usually located in theappsdirectory.
| 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. |
Restore Scenarios
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 files apps /<mount-point>
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:
docker compose exec owncloud 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
docker compose exec owncloud 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_idvalue for the storage where the file was located from theoc_storagestable and store the value for later reference. For example, if you have the following in youroc_storagestable, thenumeric_idyou should use is3if 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
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>.
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.
docker compose exec owncloud occ maintenance:data-fingerprint
Bring back ownCloud Into Normal Operation Mode
docker compose exec owncloud occ maintenance:mode --off