Backing up gitea without git user account password
I recently needed to backup my Gitea server configuration, repositories and database data. The gitea.io site does offer a page that shows the procedure on how to backup your gitea server. You can find that here: Gitea.io – Backup and Restore
Creating a user without a password – This was kind of helpfull
The su CommandA detailed explaination of the ‘su’ command
How to do it:
Easy enough right? Well no, it’s never that easy. Every goddamn thing I try to do lately is always 10 more steps than originally figured.
The problem? Well the command they start with for starters:
Switch to the user running gitea:
The issue, at least with my system which is running Ubuntu 18.04, is that the git user doesn’t have a password setup when it’s created (and I’m don’t think it should, I’m pretty sure this would break some functionality with git but please correct me if I’m wrong in this assumption.)
When you use the su (switch user) command, it asks for a password regardless if one is actually set on the user account and it won’t accept a blank password either.
So what are we to do? Well first I’ll show you what didn’t work for me:
The commands that didn’t work:686 sudo -u git ./gitea dump -c /usr/local/bin/gitea/custom/conf/app.ini
687 su -c ‘su git -c “./gitea dump -c /usr/local/bin/gitea/custom/conf/app.ini”‘
693 sudo chown -v brandon:devteam gitea-dump1544683993.zip
694 sudo chown -v brandon:devteam gitea-dump-1544683993.zip
696 chmod -v 0770 gitea-dump-1544683993.zip
If any of the above commands worked for you, please let me know what operating system your running & the circumstances in which you were able to successfully run one of the above commands.
Breif Rundown of Procedure:
First, since the above command failed when gitea tried to create the zip archive, I’m going to temporarily change the gitea direcotories permissions by getting the owner to the ‘git’ user. (just the folder, we don’t need to recurse the permissions.)
After that’s done will cd into the gitea installation directory and run the altered ./gitea dump command that will allow us to run it as the ‘git’ user.
After running the ./gitea dump command, I needed to change the permissions on the zip archive that was created by Gitea to my username. In my case, I also added group write permissions so other users within the devteam group will also have write access.
The last step is to just change the permissions of the gitea installation folder back to having the owner as ‘root’.
Let’s Get started:
The commands to temporarily change the gitea installation directory permissions:sudo -s
chown -v git: /usr/local/bin/gitea
#confirm directory permissions with ls -lah
Now we can start the backup procedure:cd /usr/local/bin/gitea
sudo -u git ./gitea dump -c /usr/local/bin/gitea/custom/conf/app.ini
chown -v brandon:devteam /usr/local/bin/gitea/*.zip
chmod -v 0770 /usr/local/bin/gitea/*.zip
mv *.zip /home/brandon/Backups
chown -v root: /usr/local/bin/gitea
#Confirm the gitea directory ownership has been changed back to ‘root’
#That’s it, Ur Done! 🙂
su -c ‘su git -c “./gitea dump -c /usr/local/bin/gitea/custom/conf/app.ini”‘
sudo chown -v brandon:devteam gitea-dump-1544683993.zip
chmod -v 0770 gitea-dump-1544683993.zip
Below is an output of the backup process: