3

I am using rsnapshot to make daily backups of a MYSQL database on a server. Everything works perfectly except the ownership of the directory is root:root. I would like it to be root:backups to enable me to easily download these backups to a local computer over an ssh connection. (My ssh user has sudo permissions but I don't want to have to type in the password every time I make a local copy of the backups. This user is part of the backups group.)

In /etc/rsnapshot.conf I have this line:

backup_script /usr/local/bin/backup_mysql.sh mysql/

And in the file /usr/local/bin/backup_mysql.sh I have:

umask 0077
# backup the database
date=`date +"%y%m%d-%h%m%s"`                                                                                             
destination=$date'-data.sql.gz'
/usr/bin/mysqldump --defaults-extra-file=/root/.my.cnf --single-transaction --quick --lock-tables=false --routines data | gzip -c > $destination
/bin/chmod 660 $destination
/bin/chown root:backups $destination

The file structure that results is:

/backups/
├── [drwxrwx---]  daily.0
│   └── [drwxrwx---]  mysql [error opening dir]
├── [drwxrwx---]  daily.1
│   └── [drwxrwx---]  mysql [error opening dir]

The ownership of the backup data file itself is correct, as root:backups, but I cannot access that file because the folder it is in, mysql, belongs to root:root.

12
  • Perhaps you could add some more chgrp commands to a cmd_postexec command.
    – meuh
    May 8, 2020 at 8:08
  • Looks like a umask issue. Try setting it to umask 002 just before you call rsnapshot May 8, 2020 at 8:47
  • I've tried setting the umask to 002. We'll see tomorrow what effect this had! May 9, 2020 at 5:38
  • 1
    Change the cron line to have umask 002; rsnapshot... instead of just rsnapshot.... Don't change the five numbers at the beginning of the line as they define when the job gets run. May 15, 2020 at 7:16
  • 1
    @meuh cmd_postexec allows me to run chown -R root:backups /backups/ which works. Shall I write that as the answer to this question or would you prefer to do it yourself? May 18, 2020 at 4:49

1 Answer 1

3

In the default /etc/rsnapshot configuration file is the following:

# Specify the path to a script (and any optional arguments) to run right
# after rsnapshot syncs files
# cmd_postexec   /path/to/postexec/script

You can use cmd_postexec to run a chgrp command on the resulting files which need their group ownership changing.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .