2

I am writing a backup script. The script is located in /usr/local/backup-scripts The files should be stored to /var/backup/subdirectory I want to run the script using cron job or systemd-timer.

I have no idea how to set the permissions correctly. Of course for testing I can sudo run the script. But what when the cron job or systemd runs the script? Do they (they=cron or systemd) have su-rights?

Unfortunately I am not that familiar with the permission in Linux so I have no idea if I have to chown the script to a special user (maybe sys???) or what the "right" way is. Appreciate every help, cheers Stefan

1 Answers1

2

System user and cron

A simple and secure way would be to create a backup-user as system user (no home folder). Then give permissions to the backup-user for the backup location:

$ adduser --system --no-create-home backup-user
$ chown -R backup-user /var/backup/subdirectory

Also you need to specify the user in the cron job.

Backup tool

While writing own backup shell scripts is fun for a little while, sooner or later it becomes hard to mange all the corner cases. So if you get tired of writing shell scripts, checkout bacula. It is definitely more work to setup, but it offers more features then self written scripts.

Simon Sudler
  • 3,931
  • 3
  • 21
  • 34
  • Good approach. However, depending on the backup sources the backup-user might need extra permissions to access all files that ought to be backed up. – PerlDuck Sep 28 '18 at 19:33
  • I agree, permission management becomes difficult in a complex environment... – Simon Sudler Sep 28 '18 at 19:58
  • I run my backup script as root so it can access all the sources. But it just depends on what you want to backup. – PerlDuck Sep 28 '18 at 20:06