plugins icon indicating copy to clipboard operation
plugins copied to clipboard

os-git-backup 1.0_1 does not initialise upstream properly, does not backup any files

Open GJKrupa opened this issue 2 years ago • 11 comments

Important notices Before you add a new report, we ask you kindly to acknowledge the following:

  • [X] I have read the contributing guide lines at https://github.com/opnsense/plugins/blob/master/CONTRIBUTING.md
  • [X] I have searched the existing issues, open and closed, and I'm convinced that mine is new.
  • [X] The title contains the plugin to which this issue belongs

Describe the bug I have tried configuring git-backup with repos in both gitlab.com and github.com and with both ssh and https remotes with the same effect. When using ssh I set up a valid deploy key on the repo with write access, when using https I set up a valid access token with write access.

When I run the initial configuration with no /conf/backup/gif folder present, I get the following error banner displayed at the top of the screen:

The following input errors were detected:

unknown error, check log for details
Saved settings, but remote backup failed.

In order to get past that stage I can shell into the /conf/backup/git and run git pull origin master && git push --set-upstream origin master. The test button then seems to operate successfully but no backup is uploaded and the file list in the banner at the top of the screen is empty. All I can see in the /conf/backup/git directory is the .git subdirectory and an identity file containing my deploy key.

To Reproduce Steps to reproduce the behavior:

  1. Create an empty repo in github or gitlab
  2. Generate a deploy key with write access to the repo
  3. Click on System->Configuration->Backups
  4. Scroll down to Git
  5. Enter details of the repository as specified in https://docs.opnsense.org/manual/git-backup.html including the private SSH deploy key
  6. Click the Setup/Test Git button
  7. See error

Expected behavior An initial backup should be committed to the repo and pushed to the remote repository and a "Backup successful" banner should appear indicating the files that were committed and pushed.

Relevant log files From the general log: git-backup unknown error, check log for details (error: src refspec master does not match any error: failed to push some refs to 'ssh://github.com/GJKrupa/repo-name.git' )

N.B. It says master (and the checked-out branch in /conf/backup/git is master) regardless of the branch name I specify in the UI.

Environment

OPNsense 22.1.8-amd64 FreeBSD 13.0-STABLE OpenSSL 1.1.1o 3 May 2022

GJKrupa avatar May 26 '22 20:05 GJKrupa

https://github.com/opnsense/plugins/issues/2882#issuecomment-1060328908 ??

AdSchellevis avatar May 27 '22 07:05 AdSchellevis

I don't believe it's the same thing. I already read that guide before I started and set the username to 'git' in the UI. The fact that I can push/pull the repo from the command-line without modifying the remote or the creds suggests there's no access issue.

GJKrupa avatar May 27 '22 22:05 GJKrupa

I'm seeing this too... it's so strange.

feld avatar Jul 29 '22 13:07 feld

The commands that are being executed can be found in the php code here: https://github.com/opnsense/plugins/blob/8bdd618652efb969ec0855b2be85af0240bbc657/sysutils/git-backup/src/opnsense/mvc/app/library/OPNsense/Backup/Git.php#L149-L167

AdSchellevis avatar Jul 29 '22 14:07 AdSchellevis

Looks like it's not attaching the upstream branch to the local branch. Running git push origin master doesn't do it, you need to have that --set-upstream (or -u) flag as well.

GJKrupa avatar Jul 29 '22 19:07 GJKrupa

Since it's removing and re-adding the origin every time, it should probably be running git branch -u _remote_ _branch_ for a clean update to the upstream.

Also, as an aside, I notice the code is using just git in a number of places where it should be using {$git}.

GJKrupa avatar Jul 29 '22 19:07 GJKrupa

changed the references to git as suggested in https://github.com/opnsense/plugins/commit/db2e4bcb0610143f6cfa413c86c0c92f80dd3db0, tried syncing to GitHub on my development machine multiple times changing branches as well, but can't reproduce an issue.

It might be an idea to reproduce the steps on your end and see which error git returns when executing the exact steps from the script.

AdSchellevis avatar Jul 30 '22 07:07 AdSchellevis

This is what I got from running the same commands (not quite in the same order but shouldn't cause any issues):

root@router:/ # mkdir /tmp/gitback-test
root@router:/ # git init /tmp/gitback-test
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: 	git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: 	git branch -m <name>
Initialized empty Git repository in /tmp/gitback-test/.git/
root@router:/ # cat > /tmp/gitback-test/identity
...
root@router:/ # chmod 600 /tmp/gitback-test/identity
root@router:/ # cd /tmp/gitback-test/ && git remote remove origin
error: No such remote: 'origin'
root@router:/tmp/gitback-test # cd /tmp/gitback-test/ && git remote add origin [email protected]:GJKrupa/opnsense-plugins-2994.git
root@router:/tmp/gitback-test # cd /tmp/gitback-test/ && git config core.sshCommand "ssh -i /tmp/gitback-test/identity -o StrictHostKeyChecking=accept-new -o PasswordAuthentication=no"
root@router:/tmp/gitback-test # cd /tmp/gitback-test/ && git push origin master
error: src refspec master does not match any
error: failed to push some refs to 'github.com:GJKrupa/opnsense-plugins-2994.git'

I'm now thinking it's just failing because there aren't any commits on the branch and nothing to do with the upstream tracking at all. I get the same if I try to push a newly-initialised repo from my MacBook until I either make an empty commit (using git commit --allow-empty) or pull the existing commits from the remote and then push.

GJKrupa avatar Jul 30 '22 09:07 GJKrupa

well, if you do have the same issue as https://github.com/opnsense/plugins/issues/3050, the hook might not have committed any local changes, in which case there isn't anything to push either. haven't thought about that at first, but could very well be the case. When you remove /conf/event_config_changed.json and the push works, it's the same issue.

AdSchellevis avatar Jul 30 '22 13:07 AdSchellevis

After fresh install of 22.7 and import of config from 22.1 and installing os-git-backup plugin, I now have this problem as well.

The following input errors were detected:

unknown error, check log for details Saved settings, but remote backup failed.

tentious avatar Aug 19 '22 22:08 tentious

I'm interested in "log for details" ;)

fichtner avatar Aug 21 '22 07:08 fichtner

This issue has been automatically timed-out (after 180 days of inactivity).

For more information about the policies for this repository, please read https://github.com/opnsense/plugins/blob/master/CONTRIBUTING.md for further details.

If someone wants to step up and work on this issue, just let us know, so we can reopen the issue and assign an owner to it.

OPNsense-bot avatar Nov 22 '22 20:11 OPNsense-bot

After fresh install of 22.7 and import of config from 22.1 and installing os-git-backup plugin, I now have this problem as well.

Facing the same issue, just did a fresh install and restored my backup, which included git-config with a self hosted repo. The git backups were working before. Now every time I try to Test the setup, I get:

[meta sequenceId="1"] git-backup unknown error, check log for details (error: src refspec master does not match any error: failed to push some refs to 'ssh://git.myserver.com/org/mybackuprepo.git' )

I can push when I SSH into the box, go to /conf/backup/git and do git push origin main (being main the branch I have configured in the git-config settings.

Any ideas?

yorch avatar Feb 16 '23 23:02 yorch