Content
You are here:
Backup script and cron job
Added by Tobias Braun almost 6 years ago
Hi,
I try to configure a cron job to do a daily backup by executin the openproject backup script openproject run backup
I created this entry with crontab -e
00 03 * * * /var/db/openproject/script/backupOpenProject
This should execute the following script:
sudo openproject run backup
echo "Nightly Backup Successful: $(date)" >> /var/db/openproject/OP_backup.log
I tried the script manually but it gives me the error
: not found exec: backup
Do I need to specify here more? I guess this is a ruby script.
Thanks,
Tobias
Replies (5)
Hi Tobias,
I would suggest you avoid running this as a root cron entry. Instead, try the following:
crontab -e -u openproject
And within the script, it should suffice to simply state
openproject run backup
.Best,
Oliver
Hi Oliver,
you mean like that?
00 03 * * * openproject run backup
KR,
Tobias
Works, Thanks!
I have a similar request but I have a Docker installation. I don't know of an equivalent "openproject" executable. I logged into the container and found the packaging/scripts/backup file but it appears to depend on APP_NAME which defaulted to 'backup' when I simply ran the script. I think I can cobble something together to create a cron job to exec into the container and pass in an environment variable APP_NAME = 'openproject' but this all appears very cumbersome. Is there an easier way?
Just to follow up with my previous challenges getting the backups to run with a docker installation...
The openproject.org guide for backups with a docker installation are here: https://www.openproject.org/operations/backup/backup-guide-docker-installation/. Unfortunately the pgdata directory is only readable by a special user and any change to the permissions will cause errors. I believe this is because backing up a PostgreSQL database is not as straightforward as copying the intermediate state of the files. I investigated using 'barman' to perform periodic "physical" backups of the database but the changes to the docker image to support barman became too complex. I instead opted to follow the same process as the openproject backup scripts and perform periodic "logical" backups of the database via pg_dump. The database snapshot(s) will then be stored under the openproject/static directory which can then be backed up using the same process as described in the openproject.org guide.
The key is how to kick off these periodic logical backups. I am a complete novice when it comes to Ruby on Rails and Rake but I noticed a Rake task called backup which will perform the pg_dump operation. Although not the best practices for a docker installation, I created a very basic script to find the container ID where openproject is running and then execute the Rake task inside that container:
#!/bin/bash
containerID=`docker ps | grep openproject | awk '{print $1}'`
docker exec -e RAILS_ENV=production $containerID bundle exec rake backup:database:create[/var/db/openproject/pgdumps/openproject-production-db.backup]
(Note that this will continue to overwrite the same file each logical backup which is find for my application; you may want to add a variable to the filename, like a date string, to preserve more than one logical backup).
I then run a cron job on the main host to periodically kick off the Rake task in the container. This Rake backup task is not as comprehensive as the backup script included in the packages directory since it only takes logical backups of the database and doesn't backup configurations, but it is a start.
I am open to hearing about a method that is better supported but hopefully this info will help someone else.
Best regards