Automated Docker Backup OpenMediaVault
🔄 RESTORE AFTER A CLEAN OMV INSTALL
If you reinstalled OMV, here’s how to restore your Docker data and containers step by step.
✅ Step 1: Install Docker on OMV
Run the official Docker installation script to install Docker manually:
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
✅ Step 2: Install Portainer (Optional but Recommended)
Use this command to install Portainer as a container:
docker volume create portainer_data
docker run -d \
-p 9000:9000 -p 8000:8000 \
--name=portainer \
--restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v portainer_data:/data \
portainer/portainer-ce
You can now access Portainer at: http://<your-nas-ip>:9000
✅ Step 3: Extract Your Last Archive
Assuming your backup archive is a tar file like
backup_2025-05-10.tar.gz
:
cd /srv/personal/
tar -xzvf backup_2025-05-10.tar.gz
This will extract all Docker-related folders and SQL dump files under
/srv/personal/backups
.
🛠️ Full Restore Guide for Nextcloud and Immich (Docker Setup)
This step-by-step guide explains how to restore your Docker-based Nextcloud and Immich setup from backups, including Docker data, config files, and both databases.
🧭 Overview of Restore Order
- Stop Docker
- Restore Docker volumes, containers, network, swarm, config
- Start Docker
- Restore Nextcloud MySQL and Immich PostgreSQL databases
- Restart the application stacks (Nextcloud & Immich)
- Verify successful restoration
🔹 Step 1: Stop Docker
To avoid any conflicts during restore, stop the Docker service:
sudo systemctl stop docker
🔹 Step 2: Restore Docker Data
Restore all required Docker directories from your backup:
BACKUP_DIR="/srv/personal/backups"
sudo rsync -aHAX --delete "$BACKUP_DIR/volumes/" /var/lib/docker/volumes/
sudo rsync -aHAX --delete "$BACKUP_DIR/containers/" /var/lib/docker/containers/
sudo rsync -aHAX --delete "$BACKUP_DIR/network/" /var/lib/docker/network/
sudo rsync -aHAX --delete "$BACKUP_DIR/swarm/" /var/lib/docker/swarm/
sudo rsync -aHAX --delete "$BACKUP_DIR/config/" /var/lib/docker/config/
🔹 Step 3: Start Docker
Once data is restored, start Docker again:
sudo systemctl start docker
🔹 Step 4: Restore Nextcloud MySQL Database
Ensure the Nextcloud database container is running. Then restore the backup:
NEXTCLOUD_DB_DUMP="/srv/personal/backups/nextcloud-db_YYYY-MM-DD_HH-MM.sql"
cat "$NEXTCLOUD_DB_DUMP" | docker exec -i nextcloud_db sh -c 'exec mysql -uroot -p277697 nextcloud'
🔹 Step 5: Restore Immich PostgreSQL Database
✅ 1. Stop Immich Services
Stop the Immich server or the full stack to prevent any write conflicts:
docker stop immich_server
Or:
docker compose down
✅ 2. Copy SQL Backup into Container (optional)
docker cp /srv/personal/Backups/immich_db_backup.sql immich_postgres:/tmp/immich_db_backup.sql
✅ 3. Drop and Recreate the Immich Database (clean method)
Enter the PostgreSQL shell:
docker exec -it immich_postgres psql -U postgres
Then run inside the shell:
DROP DATABASE IF EXISTS immich;
CREATE DATABASE immich;
\q
✅ 4. Restore Immich SQL Dump
If copied to container:
docker exec -i immich_postgres psql -U postgres immich < /tmp/immich_db_backup.sql
Or from host directly:
docker exec -i immich_postgres psql -U postgres immich < /srv/personal/Backups/immich_db_backup.sql
✅ 5. Restart Immich
docker start immich_server
Or:
docker compose up -d
🔹 Step 6: Restart Application Stacks
Start Nextcloud and Immich stacks either via Portainer or Compose:
docker compose -f /path/to/nextcloud/docker-compose.yml up -d
docker compose -f /path/to/immich/docker-compose.yml up -d
🔹 Step 7: Verify Services and Databases
Access services in your browser:
- Nextcloud:
http://<your-nas-ip>:8080
- Immich:
http://<your-nas-ip>:2283
Verify Database Connection
For Nextcloud:
docker exec nextcloud_db mysql -uroot -p277697 -e "USE nextcloud; SHOW TABLES;"
For Immich:
docker exec -it immich_postgres psql -U postgres -d immich -c "\dt"
Fixing Nextcloud Directory and Permission Errors
If you're encountering errors in your Nextcloud setup like "Your data directory is invalid" or "Cannot write into 'apps' directory", don't worry. These are usually related to permissions and missing files. Here's how to fix them step by step.
1. Your Data Directory is Invalid
This error means that Nextcloud can't verify the data directory. It expects a
file named .ncdata
in the root of the data directory with
specific content.
Solution:
Run the following command to create the required file:
echo "# Nextcloud data directory" | sudo tee /srv/personal/nextcloud/data/.ncdata
Then fix the file permissions:
sudo chown -R 33:33 /srv/personal/nextcloud/data
Note: UID 33 and GID 33 typically refer to the
www-data
user used by Docker containers. If unsure, check with:
docker exec -it <container-name> id
2. Cannot Write into "apps" Directory
This error occurs when the Nextcloud container doesn't have write access to
the apps
or themes
directories.
Solution:
Run these commands to fix ownership:
sudo chown -R 33:33 /srv/personal/nextcloud/apps
sudo chown -R 33:33 /srv/personal/nextcloud/themes
If you're using Docker volumes, ensure the inner folders are also writeable:
sudo chown -R 33:33 /var/lib/docker/volumes/nextcloud_nextcloud_html/_data
3. Optional: Disable the App Store
If you still face issues, you can temporarily disable the App Store in your
config.php
file.
Edit Configuration:
sudo nano /var/lib/docker/volumes/nextcloud_nextcloud_html/_data/config/config.php
Add or modify this line:
'appstoreenabled' => false,
4. Restart the Container
Apply all changes by restarting your Nextcloud container:
docker restart nextcloud
Conclusion
By following these steps, you can resolve the common Nextcloud permission and directory errors in a Docker-based setup. Regular maintenance and proper file permissions are key to a stable and secure Nextcloud server.
✅ Restore Complete!
You’re now fully restored and operational. Welcome back online!
✅ Final Thoughts
You’ve now got a rock-solid, fully automated Docker backup strategy for your OpenMediaVault NAS. Even if your system crashes or gets wiped, you’ll be able to bring everything back — containers, volumes, settings — in just minutes.