1

I'm trying to run my custom backup script through rsnapshot. It simply clones a given git repository to the current working directory. It works fine when run without rsnapshot.

/etc/rsnapshot.config:

backup_script   /usr/local/bin/gitbackup.py -r https://foo.bar/myrepo.git -u username -f /root/.pwd git/myrepo.git/

This creates an directory with a .git below myrepo/.git at the backup location and an error:

# rsnapshot -v daily
[...]
error: could not lock config file /var/cache/rsnapshot/tmp/myrepo/.git/config: No such file or directory
fatal: could not set 'remote.origin.fetch' to '+refs/heads/*:refs/remotes/origin/*'

Both, the rsnapshot user and root, got an ~/.gitconfig in their home directories.

Also tried to run it with sudo. This results in:

Cloning into 'myrepo'...
/bin/rm -rf /var/cache/rsnapshot/tmp/ 
/bin/rm: cannot remove '/var/cache/rsnapshot/tmp/myrepo/.git': Directory not empty
----------------------------------------------------------------------------
rsnapshot encountered an error! The program was invoked with these options:
/usr/bin/rsnapshot -v daily 
----------------------------------------------------------------------------
ERROR: Warning! /bin/rm failed.
ERROR: Could not rm_rf("/var/cache/rsnapshot/tmp/");
rm -f /var/run/rsnapshot.pid 
fatal: remote-curl: fetch attempted without a local repo

Any idea what's going wrong? Perhaps some env vars for git have to be set?

Dirk Eschler
  • 111
  • 3
  • 1
    does "/var/cache/rsnapshot/tmp/myrepo/.git/config" actually exist? What does an "ls -l" on this file do? – wazoox Feb 19 '18 at 14:24
  • No, /var/cache/rsnapshot/tmp/ is empty. I suppose that's the temp directory used by rsnapshot. – Dirk Eschler Feb 19 '18 at 16:06
  • That's a good pointer though. I might have to change to a working directory explicitly in my backup script. I'll try that and report back. – Dirk Eschler Feb 19 '18 at 16:09

1 Answers1

0

The problem was an unspecified working directory. Apparently rsnapshot uses /var/cache/rsnapshot/tmp/ by default and /var/cache/rsnapshot is read- and writeable by the rsnapshot user only (whereas the backup_script runs as root).

My backup script now changes the working directory, checks out to /home/rsnapshot/git_backup and this directory is backup'ed using a normal backup directive.

backup_script   /usr/local/bin/gitbackup.py -r https://foo.bar/myrepo.git -u username -f /root/.pwd -w /home/rsnapshot/git_backup  git_tmp/myrepo.git/
backup  /home/rsnapshot/git_backup/ localhost_git/

Now i got the problem, that the synced (not the cloned) checkouts below /var/cache/rsnapshot/daily.0/localhost_git only contain a ~/.git directory and nothing else, but that's a different issue.

Dirk Eschler
  • 111
  • 3