Skip to content

Instantly share code, notes, and snippets.

@technikamateur
Last active August 3, 2023 09:47
Show Gist options
  • Save technikamateur/b612421ce156c174e6f4e637985184c8 to your computer and use it in GitHub Desktop.
Save technikamateur/b612421ce156c174e6f4e637985184c8 to your computer and use it in GitHub Desktop.
Gitea systemd daily backup
# Contents of /etc/systemd/system/gitea-backup.service
[Unit]
Description=This service backups gitea
[Service]
Type=oneshot
ExecStart=/usr/local/bin/ultimative-backupper
# Contents of /etc/systemd/system/gitea-backup.timer
# run 'systemctl daemon-reload' and 'systemctl enable gitea-backup.timer' after creating this file
[Unit]
Description=Run service backup every two days
[Timer]
OnCalendar=*-*-* 22:00:00 # this means daily at 22:00. More information: https://www.man7.org/linux/man-pages/man7/systemd.time.7.html
AccuracySec=5min
[Install]
WantedBy=timers.target
#!/bin/bash
# create this file as root under '/usr/local/bin/ultimative-backupper' to be consistent with the systemd files
# afterwards run 'chmod 750' on this file!
BACKUP_LOCATION=PATH_TO_BACKUP_LOCATION # owner+group should be git and 750
systemctl stop gitea.service && sudo -u git /usr/local/bin/gitea dump -c /etc/gitea/app.ini -w PATH_TO_WORKING_DIR_SPECIFIED_IN_APP.INI -f $BACKUP_LOCATION/gitea-dump-$(date +"%Y-%m-%d").zip && systemctl start gitea.service
file_num=$(ls $BACKUP_LOCATION | wc -l)
if [[ $file_num -gt 90 ]]; then # 90 backup are kept. You can enter any valid number
ls -1t $BACKUP_LOCATION | tail -1 | xargs rm -f
fi
@technikamateur
Copy link
Author

This manual expects that you've setup your gitea installation with a systemd service as described in the docs: https://docs.gitea.com/next/installation/linux-service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment