I created a cron job as root with the command:
crontab -e
Then I added 0 4 24-31 * 4 /home/backupscript.sh
after the last line.
The output of crontab -e
looks like this:
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
0 4 24-31 * 4 /home/backupscript.sh
My script at /home/backupscript.sh looks like this:
cd "/home/backups/"
datestring="$(date +%Y-%m-%d)"
sudo /opt/bitnami/ctlscript.sh stop
sudo tar -pczvf ${datestring}.openproject-backup.tar.gz /opt/bitnami
sudo /opt/bitnami/ctlscript.sh start
It works fine when I run it with bash /home/backupscript.sh
.
#!/bin/bash
?0 4 24-31 * 4 bash /home/backupscript.sh
, maybe the script only needs a execute flag (chmod +x /home/backupscript.sh
)