My question: Does anyone have a technique to automate the daily scheduling of backups using the official restic container image that they can share?
My problem:
I have a Docker container that is set to run continously based on the official restic docker image. If I run the restic commands in the container, I can manually backup from one local folder to another local folder. Everything is working except I have to manually log in and run the portainer command. However, I’m not sure how to get the backup command or any commands inside the restic to run on a schedule. The container did not seem to have an internal crontab or something like that.
What I tried:
I’m not sure how to get the backup command or any commands inside the restic to run on a schedule. The container did not seem to have an internal crontab or something like that. Unfortunately, my ASUSTOR NAS unlike other NAS units has no ability to schedule jobs. I tried using crontab by cracking into the underlying OS but that did not work and I would prefer a pure container solution and that config would be wiped without warning if there was an update, so not a great solution, and it did not work for me. I also tried setting up a side car container to send commands but was not successful and that involves giving root access or something like that which seems insecure, but in any case could not find a container image that would do the job securely.
Details:
The restic version is the latest in hub.docker.io, currently 1.80.
Workflow:
Here is my complete workflow for setting up my persistent restic container for (so far) only manual backup jobs.
Creating a restic container for local backup
Phase 1: Creating the Restic “Service” Container in Portainer
We went to Containers → + Add container and configured the following settings:
- Name and Image:
- Set the Name to
Backup-OneDrive-Restic-Local-User1. - Set the Image to
restic/restic:latest.
- Command and Entrypoint:
- In the “Command & Logging” tab, we overrode the Entrypoint to be
shand the Command to be-c 'tail -f /dev/null'. - Purpose: This was the crucial fix to make the container run a command that keeps it alive and idle, ready for our instructions.
- Volume Mapping:
- In the “Volumes” tab, we created two Bind mounts to connect folders inside the container to your real folders on the NAS.
- Source: Mapped the container’s
/sourcepath to your NAS’s/volume2/Sync_OneDrive_User1path. - Destination: Mapped the container’s
/backuppath to your NAS’s/volume2/Backup_OneDrive_User1path.
- Environment Variables:
- In the “Env” tab, we set two variables to automatically configure restic.
RESTIC_REPOSITORYwas set to/backup, telling restic which container path to use for the backup.RESTIC_PASSWORDwas set to your secret password, so you never have to type it in a command.
- Restart Policy:
- In the “Restart policy” tab, we set the policy to Unless stopped.
- Purpose: This ensures your backup container will automatically start if you ever reboot your NAS.
- Deployment: You clicked Deploy the container, which created and started the service based on all these rules.
Phase 2: First-Time Initialization and Manual Backup
- Connected to the Container: We used Portainer’s Exec console feature to open a command prompt inside the running container, making sure to use the correct
/bin/shshell. - Initialized the Repository: Inside the console, you ran the one-time command
restic init.
- Result: This created the necessary file and folder structure for a restic repository inside your
/volume2/Backup_OneDrive_Userfolder.
- Ran the First Backup: You then ran the command
restic backup /source.
- Result: Restic successfully scanned all 176 GB of your data from the source folder, compressed it, encrypted it, and saved it as the first “snapshot” in your backup repository. This took about one hour.