Using systemd timers for backup with IDCF Object Storage
Posted on
My wiki pages were originally planned to be backuped to Dropbox or Google Drive which have user friendly interface and inherently folder synchronization. These cloud storage services use OAuth 2.0 authentication for API. It's not a problem for operations. But in a disposable environment such as Docker, unfortunately it is difficult to generate an access token and set it to containers interactively. That is why I switched to IDCF Object Storage for my backup plan.
My wiki pages were originally planned to be backuped to Dropbox or Google Drive which have user friendly interface and inherently folder synchronization. These cloud storage services use OAuth 2.0 authentication for API. It’s not a problem for operations. But in a disposable environment such as Docker, unfortunately it is difficult to generate an access token and set it to containers interactively. That is why I switched to IDCF Object Storage for my backup plan.
Backup to IDCF Object Storage
I recently created a idcf-storage-sync Docker image for this purpose. It’s a simple wrapper of s3cmd sync based on Docker container.
Systemd Timers
We use a systemd timer as an replacement of crontab. A OnUnitActiveSec directive is used for executing a unit which is defined at Unit directive every four hours.
[Unit] Description=MoinMoin Every four hours Timer [Timer] OnUnitActiveSec=4hour Unit=%p@%i.service [Install] WantedBy=timers.target [X-Fleet] MachineOf=%p@%i.service
MoinMoin Backup Service
I use a etcd cluster as a central repository for avoiding complex probrems of leader election. So it might be a ordinary use of etcdctl, we should get values from etcd and set to environment variables before ExecStart directive in my environment.
A reduced wiki pages archive is saved in a CoreOS host directory. We could sync files in the directory and IDCF Object Storage’s bucket using s3cmd sync via idcf-storage-sync container. We set a --delete-removed flag for letting s3cmd remove any files not in the local directory. And the last line would clean up old files before two days.
Set timer for a target service
We submit and load a target unit file and timer unit file. And we only start a timer unit for scheduling.