透過 rsnapshot 進行 Git 克隆失敗

透過 rsnapshot 進行 Git 克隆失敗

我正在嘗試透過 rsnapshot 運行我的自訂備份腳本。它只是將給定的 git 儲存庫複製到目前工作目錄。在沒有 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/

這會在備份位置的 myrepo/.git 下建立一個帶有 .git 的目錄,並出現錯誤:

# 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/*'

rsnapshot 使用者和 root 都在其主目錄中獲得了 ~/.gitconfig。

也嘗試用 sudo 運行它。這導致:

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

知道出了什麼問題嗎?也許必須設定一些 git 的環境變數?

答案1

問題是未指定的工作目錄。顯然 rsnapshot/var/cache/rsnapshot/tmp/預設使用且/var/cache/rsnapshot只能由 rsnapshot 使用者讀寫(而 backup_script 以 root 身分運行)。

我的備份腳本現在更改工作目錄,簽出/home/rsnapshot/git_backup並使用普通指令備份目錄backup

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/

現在我遇到了問題,下面的同步(不是克隆)簽出/var/cache/rsnapshot/daily.0/localhost_git僅包含一個~/.git目錄,沒有其他內容,但這是一個不同的問題。

相關內容