0

I'm on Ubuntu Server 20.04 LTS and what I'm trying to do is to set the cron job for automysqlbackup utility. When I installed automysqlbackup I noticed that the cron.daily/automysqlbackup was created inside the etc folder. In the automysqlbackup file there are the following lines:

#!/bin/sh
test -x /usr/sbin/automysqlbackup || exit 0
/usr/sbin/automysqlbackup

Why do we need these and what do they do?

Can I delete that automysqlbackup file and set everything up through sudo crontab -u username -e for my user?

1 Answer 1

2

Why do we need these and what do they do?

#!/bin/sh specifies that the cron “script” runs with /bin/sh (it’s a normal shell script). This is a shebang.

test -x /usr/sbin/automysqlbackup || exit 0 checks whether /usr/sbin/automysqlbackup exists and is executable; if it isn’t, it exits the script silently. This line is useful to avoid an error if automysqlbackup is removed but its cron job isn’t — which happens if the package is removed, not purged. Technically, it works as follows: test -x /usr/sbin/automysqlbackup exits with code 0 if the file is executable, 1 otherwise. || causes the shell to look at the exit code of the previous command; if it’s 0, the rest of the line is ignored, otherwise it’s executed; exit 0 causes the shell to exit with exit code 0 (no error).

/usr/sbin/automysqlbackup runs automysqlbackup.

Can I delete that automysqlbackup file and set everything up through sudo crontab -u username -e for my user?

Yes, you can; the package is set up correctly so that your removal will be remembered, and the file won’t be restored on package upgrades. Note that you don’t need sudo here, crontab -e as the user works just as well. You will however need to ensure that the user has all the necessary permissions for the backup (in MySQL and in whatever storage the backup goes to).

I would suggest considering instead whether there is any particular reason the default daily cron job isn’t appropriate for you; if there isn’t, keep it instead of setting up your own.

23
  • 1
    See the update. The existing cron.daily job will run once a day, using whatever configuration you’ve defined for automysqlbackup. It should work just fine for your purposes. Commented Aug 30, 2021 at 9:08
  • 1
    anacron (see man anacron) is a utility which ensures jobs are run at certain intervals, even if the system is powered down. See also Is it true that “cron.daily runs anacron everyhour”?, How does anacron determine daily, weekly and monthly job to run?, How does anacron work if it's not a daemon? and related posts. Commented Aug 30, 2021 at 9:15
  • 1
    Ah right, you don’t have anacron installed (which is fine). The crontab entry tests to see whether anacron is installed, and if it isn’t, runs the cron.daily entries using run-parts. Commented Aug 30, 2021 at 9:21
  • 1
    If you want to have all your cron.daily jobs run at a different time, then yes. Commented Aug 30, 2021 at 9:30
  • 1
    I don’t think you need anything else for weekly and monthly backups, automysqlbackup takes care of them when run daily. Commented Aug 30, 2021 at 9:31

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.