Gogs backup in python cron job


#1

Hi all,

I was working on a python script that uses subprocess to run the gogs backup command to take a backup, then upload the newly minted archive to S3. Naturally, I would schedule this as a cron job, but when I looked at the output I found the following error:

2017/12/18 13:00:02 [FATAL] [...g/setting/setting.go:571 NewContext()] Expect user 'gogs' but current user is:

Since the INSTALL_LOCK is set in the app.ini I was encountering an issue where the current user was not the RUN_USER. In this case the fatal error is reporting that the current user is an empty string. Digging into https://github.com/gogits/gogs/blob/master/pkg/user/user.go it appears that this user check is looking at the environment variable USER which must not be set either when running this in cron or when using subprocess in script.

The solution was to simply add os.environ['USER'] = 'gogs' to my python script. Hope this saves you all some grief if you try the same thing.


#2

Of course, it is logical to assume that even in the manual it is written about a specially selected user for gogs processes, but it seems to me that if you made a backup script on the bash, then you could simply set the key on the user’s executable + if it is in the scheduler itself, too key, on behalf of which user run the script execution.

Sorry for my English =)