Let us learn more about the Nextcloud docker backup restore and how to set up the backup. At Bobcares our Docker hosting support services can guide you through the process.
Nextcloud using docker backup and update
We can backup and update a Nextcloud instance using docker compose. We have to consider some of the elements that make them important. Here are a few examples:
- Firstly, the failure of the Raspberry Pi.
- A hacker or a program attacking the system.
- Deleting data by accident or on purpose as a result of an application or human mistake.
- Natural causes or disasters.
We can set up and select the location, Retention time, and when to backup. This improves data security.
Backup the docker volume
To back up a Docker data volume, start a new container. Start it with the volume to run the backup command. The data for the volume is available in the Docker data list. However, the Docker daemon should handle the volumes. Let us now go through the necessary settings to set up the backup.
After that, we have to confirm the SSH public key. Create an SSH keypair and submit the public key to the remote server to log in without the login details.
Docker image for the container
For the next step to set up the Nextcloud docker backup restore we require a Docker image. The image should include the following tools: OpenSSH and rsync. As a result, we use the Alpine Docker image and install the packages. The Dockerfile is as follows:
FROM alpine:latest
RUN apk update && apk add openssh rsync
Docker-compose
After that, we must define the data volume and the command to use the actual backup. We can do this with a lengthy command line statement, however, it is better to use docker compose for clarity.
We can create the docker compose yml file in the same folder as the Dockerfile. Follow the command lines given below to set this up:
version: '3'
services:
backup-ncdata:
build: .
volumes:
- ncdata:/data:ro
- /home/pi/.ssh/id_rsa:/root/.ssh/id_rsa:ro
command: rsync -axh -e "ssh -p 22 -o StrictHostKeyChecking=no"
--rsync-path="rsync
--fake-super"
--links --delete
--info=progress2 "/data/" "user@abcd.com:ncdata" volumes: ncdata: external: true
After that, to back up the volume ncdata, we have to define a single service backup ncdata.
build
. This shows that the service image is to create from the Dockerfile in the same folder.ncdata:/data:ro
. Read only volume ncdata scale in the container at /data to backup./home/pi/.ssh/id_rsa:/root/.ssh/id_rsa:ro
: Use the host’s SSH private key.command: ..."
. This is for backing up the data with rsync. The options are present in the rsync document.--rsync-path="rsync --ab-cd"
. This is critical to keep the owner and group of a file. We can do this if there are no root functions on the remote server.--info=progress2
. Finally, this command line will show the whole progress.
- Finally, to execute the backup, enter the following command in the docker compose file’s folder:
run docker-compose backup-ncdata —rm.
After the backup, the —rm option removes the container.
Backup script
It is better to enable the repair mode during backup to avoid data issues or errors. Everything is present in the shell script backup NextCloud sh. Replace home pi backup with the location of the Dockerfile and docker compose file.
#!/bin/bash
# Enable maintenance mode
docker exec -i nextcloudpi sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --on
# Backup the ncdata docker volume
# Full path to docker-compose, otherwise cron job fails
/usr/local/bin/docker-compose -f /home/pi/backup/docker-compose.yml run --rm backup-ncdata
# Disable maintenance mode docker exec -i nextcloudpi sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --off.
Cron job
To execute the backup every night, open the crontab using crontab -e. Add the following line to begin the backup at 3 a.m. every day:
0 3 * * * /home/pi/backup/backup-nextcloud.sh
Restore
We don’t have one unless we restore the data from the backup. It will reverse the whole procedure. Restore the data to a docker volume. After that use the volume to launch a new NextcloudPi. Build a new volume by running docker volume:
create name ncdata restore.
Here is the docker compose yml
file to restore the two ncdata
services. The restore service copies the data to a Docker volume. The nextcloudpi
service will execute Nextcloud with the recovered data.
version: '3'
services:
restore-ncdata:
build:
volumes:
- ncdata-restore:/data
- /home/pi/.ssh/id_rsa:/root/.ssh/id_rsa:ro
command: rsync -axh -e "ssh -p 22 -o StrictHostKeyChecking=no" --rsync-path="rsync --fake-super" --links --delete --info=progress2 "user@abcd.com:ncdata/" "/data"
nextcloudpi:
image: ownyourbits/nextcloudpi-armhf
command: "192.168.2.212"
ports:
- "802:80"
- "4432:443"
- "44432:4443"
volumes:
- ncdata-restore:/data
- /etc/localtime:/etc/localtime:ro container_name: nextcloudpi-restored restart: unless-stopped
volumes:
ncdata-restore:
external: true
After that step, Docker-compose run rm restore ncdata will restore the data. Then, docker compose up -d a new NextcloudPi with the recovered data.
[Need assistance with similar queries? We are here to help]
Conclusion
To sum up, we have now learned how to set up the NextCloud docker backup restore. Need help with docker? Get in touch with our Docker Hosting support services.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
var google_conversion_label = "owonCMyG5nEQ0aD71QM";
0 Comments