mbtamuli's scratchpad To infinity and beyond

Backup files to git repo before shutdown

I have a few files that I want to push to a remote repository just before shutdown. It could be many use cases, but mine is, I want my dotfiles synced to mbtamuli/dotfiles.

Well, the approach is simple

  • setup a small script to do git push
  • have a systemd service
  • What? You thought there’d be a ton of steps? Sorry to dissapoint. :grin:
  • profit! :sunglasses:

Create another file and do whatever you need /usr/local/bin/backup_work.sh


cd /path/to/git/repo
git add .
git commit -m "Daily Backup"
git push origin master

Add executable permissions

chmod +x /usr/local/bin/backup_work.sh

Create a file at /etc/systemd/system/backup-work.service. Change the user and group!

Description=Backup files to git repo
Before=shutdown.target reboot.target halt.target


WantedBy=halt.target reboot.target shutdown.target