christianspecht / scm-backup

Makes offline backups of your cloud hosted source code repositories
https://scm-backup.org/
GNU General Public License v3.0
58 stars 20 forks source link

Backup failed: Target directory is not empty #73

Closed creativesuspects closed 1 year ago

creativesuspects commented 1 year ago

I'm using SCM Backup 1.7.0.6090ea9 on a freshly installed Windows 11 machine. The target directory is located on an external (USB) drive which has also been used to make SCM backups on my previous machine. Any idea why SCM Backup won't update or overwrite the existing SCM backups? I could of course just delete the old backups and start from scratch, but I was wondering if there's another way to get this to work without deleting everything first.

christianspecht commented 1 year ago

Hard to tell without additional information.

Does SCM Backup output any error messages?
Do you have a logfile for me?

I have zero experience with Windows 11, but maybe it's a permission thing? Maybe your current Windows user doesn't have permissions to overwrite the files that were created by your old machine's Windows user?

creativesuspects commented 1 year ago

Here's the log for the failed backup. I've masked some details. I had already reset the permissions and ownership of the files after transferring them to the new machine and I was executing SCM Backup under my Windows user which has Administrator priviliges.

2022-12-19 12:12:15.3966|INFO|ScmBackup|SCM Backup 1.7.0.6090ea9 
2022-12-19 12:12:15.4142|INFO|ScmBackup|https://scm-backup.org/ 
2022-12-19 12:12:15.4142|INFO|ScmBackup|Operating system: Microsoft Windows 10.0.22621 
2022-12-19 12:12:15.4640|INFO|ScmBackup|Backing up config files 
2022-12-19 12:12:15.4640|INFO|ScmBackup|Getting repositories for source 'Bitbucket' from hoster 'bitbucket' 
2022-12-19 12:12:18.9247|INFO|ScmBackup|Trying to find SCMs on this machine... 
2022-12-19 12:12:19.0137|INFO|ScmBackup|Found Git 2.39.0.windows.1  
2022-12-19 12:12:19.0137|INFO|ScmBackup|Backing up source: Bitbucket 
2022-12-19 12:12:19.0412|INFO|ScmBackup|  Git: https://bitbucket.org/.../....git 
2022-12-19 12:12:19.1267|ERROR|ScmBackup|Target directory is not empty: X:\SCMBackup\Bitbucket\...#...\repo 
2022-12-19 12:12:19.1267|ERROR|ScmBackup|Backup failed! 
2022-12-19 12:12:19.1267|ERROR|ScmBackup|The application will close in 5 seconds! 

After deleting the old backups the new backups and consecutive backups were working just fine.

creativesuspects commented 1 year ago

By the way, it's not a huge issue, because I was able to solve it by deleting the previous backups before making the new backups. I was just wondering if you knew what could've caused this error.

christianspecht commented 1 year ago

From the top of my head, no.
But I poked around a bit, because I was curious:

The error message in the log is generated in this line.

This is the method that actually pulls via Git from the remote repository.
The error is generated in one of the checks before pulling: when the backup directory is no valid Git repo, but already exists and is not empty.

In your case, the directory obviously is a Git repo, so why is it not recognized as one?
Here's the method that determines if it's a Git repo - it just calls git rev-parse --is-bare-repository and checks the result.

So all I can tell is that Git doesn't recognize the backups from your old machine as valid Git repos, but I don't know why.

creativesuspects commented 1 year ago

Thanks for looking into it. Fortunately moving to a new machine is not something I have to do very often. 😊

mike-cochrane commented 1 year ago

I have come across a similar issue to this and it seems to be related to an security update that was implemented for git.

I'm using git 2.39.2.windows.1

If I run that git rev-parse command against the backup of the repo I get the following

fatal: detected dubious ownership in repository at '//blah'
'//blah' is owned by:
        'x'
but the current user is:
        'y'
To add an exception for this directory, call:

        git config --global --add safe.directory '%(prefix)///blah'

This is on a UNC path so might have to check how to fix the ownership

mike-cochrane commented 1 year ago

This worked for me after updating the owner of the folder to be the same as the user running SCM Backup