Nextcloud (snap version) backup
info
Official documentation: Nextcloud Snap
danger
This operation could be risky using ssh remote connection since the process could be terminated if the connection is lost. It is recommended to do this operation locally (systemd timer).
Backup
- Check current state by executing
snap logs nextcloud
Example output
❯ sudo snap logs nextcloud
2024-08-29T00:00:16Z nextcloud.logrotate[584775]: considering log /var/snap/nextcloud/current/logs/mysql_errors.log
2024-08-29T00:00:16Z nextcloud.logrotate[584775]: Now: 2024-08-29 00:00
2024-08-29T00:00:16Z nextcloud.logrotate[584775]: Last rotated at 2024-08-27 00:00
2024-08-29T00:00:16Z nextcloud.logrotate[584775]: log does not need rotating (log has been rotated at 2024-8-27 0:0, that is not week ago yet)
2024-08-29T00:00:16Z systemd[1]: snap.nextcloud.logrotate.service: Deactivated successfully.
2024-08-29T01:07:00Z nextcloud.renew-certs[599165]: Saving debug log to /var/snap/nextcloud/current/certs/certbot/logs/letsencrypt.log
2024-08-29T01:07:01Z nextcloud.renew-certs[599165]: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2024-08-29T01:07:01Z nextcloud.renew-certs[599165]: No renewals were attempted.
2024-08-29T01:07:01Z nextcloud.renew-certs[599165]: No hooks were run.
2024-08-29T01:07:01Z nextcloud.renew-certs[599165]: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Stop the Nextcloud snap service
sudo snap stop nextcloud
check the logs again to make sure the service is stopped
Example output
❯ sudo snap logs nextcloud
2024-08-29T12:29:42Z systemd[1]: Stopped snap.nextcloud.php-fpm.service - Service for snap application nextcloud.php-fpm.
2024-08-29T12:29:42Z systemd[1]: snap.nextcloud.php-fpm.service: Consumed 17h 23min 13.479s CPU time, 28.2G memory peak, 0B memory swap peak.
2024-08-29T12:29:42Z systemd[1]: Stopping snap.nextcloud.redis-server.service - Service for snap application nextcloud.redis-server...
2024-08-29T12:29:42Z systemd[1]: snap.nextcloud.redis-server.service: Deactivated successfully.
2024-08-29T12:29:42Z systemd[1]: Stopped snap.nextcloud.redis-server.service - Service for snap application nextcloud.redis-server.
2024-08-29T12:29:42Z systemd[1]: snap.nextcloud.redis-server.service: Consumed 44min 59.826s CPU time, 18.7M memory peak, 0B memory swap peak.
2024-08-29T12:29:42Z systemd[1]: Stopping snap.nextcloud.renew-certs.service - Service for snap application nextcloud.renew-certs...
2024-08-29T12:29:42Z systemd[1]: snap.nextcloud.renew-certs.service: Deactivated successfully.
2024-08-29T12:29:42Z systemd[1]: Stopped snap.nextcloud.renew-certs.service - Service for snap application nextcloud.renew-certs.
2024-08-29T12:29:42Z systemd[1]: snap.nextcloud.renew-certs.service: Consumed 6.246s CPU time, 75.8M memory peak, 0B memory swap peak.
- Backup the Nextcloud data directory
sudo snap save nextcloud
- Restart the Nextcloud snap service
sudo snap start nextcloud
- Copy or move the backup file to a safe location
I have a local NAS shared folder mounted on my server. I will move the backup file to that location.
cp /var/lib/snapd/snapshots/TBD /mnt/home-drive-2/nextcloud-backups/
info
Step 1 and 3 are optional. but recommended.
Delete the backup snapshot
- Check the list of snapshots
sudo snap saved
- Delete the snapshot
sudo snap forget <snapshot-id>
danger
The snap backup is not incremental. It will create a new backup every time you run the command.
Restore
- Move the backup file to
/var/lib/snapd/snapshots/
sudo cp /mnt/home-drive-2/nextcloud-backups/TBD /var/lib/snapd/snapshots/
- Find the snapshot ID
sudo snap saved
- Restore the snapshot
sudo snap restore <snapshot-id>
danger
- Before restoring the snapshot, ensure Nextcloud snap is installed.
- Restoring the snapshot will overwrite the current data
Automate the backup process
It is recommended to automate the backup process using a systemd timer. Checkout my another post about systemd timer here.
{
"id": "ca0031d5388644ad85ebbb1f610a95ed",
"name": "Huma Finance Notifications V2",
"inputs": [],
"titles": { "active": false },
"version": "v1",
"eventTypes": [
{
"name": "Important Pool Updates",
"type": "fusion",
"fusionEventId": {
"type": "value",
"value": "2b205aa9cf9e4a63821e839cde2463ec"
},
"sourceAddress": { "type": "value", "value": "*" },
"useCustomIcon": false,
"optOutAtSignup": false,
"selectedUIType": "TOGGLE",
"tooltipContent": "Notifications about important changes to a pool you\\u0027re participating in (e.g. pool liquidity cap updates)",
"topicGroupName": ""
}
],
"contactInfo": {
"sms": { "active": false, "supportedCountryCodes": [] },
"email": { "active": true },
"telegram": { "active": false }
},
"walletChain": "Celo",
"isContactInfoRequired": true
}
You can install my Nextcloud backup script to automate the backup process weekly.