Skip to content

Setup Periodic Backups

Akash Rajpurohit edited this page Dec 20, 2024 · 6 revisions

There are mainly two ways to set up periodic backups for git-sync:

  1. Use the --cron flag or the cron option in the config file to set up git-sync in cron mode.
  2. Use the default flags and set up cronjobs yourself on your system.

Using --cron or cron option

With the 0.7.0 release, we now have a dedicated option to run git-sync in cron mode. All you need to do is to add the cron option in your config file or use the --cron flag.

Run in Background via SystemD service

If you are using --cron option, you need to ensure that the service is always running in the background. For that you can use SystemD service to keep running it in background. You can find the example gitsync.service file and instructions of setting it up here

Run in Background via Docker

Apart from running it via SystemD, you can also opt to run git-sync via Docker.

Setup cronjobs yourself

If you don't want to use the in-built --cron option, you can still go ahead and setup cronjobs on your system directly to run git-sync periodically. Here are few ways to setup cron job based on different operating system.

Unix-based Systems

You can set up periodic backups using cron jobs or systemD timers. For example, to back up your repositories every day at 12:00 AM, you can add the following cron job:

0 0 * * * /path/to/git-sync

Replace /path/to/git-sync with the path to the git-sync binary.

Windows

You can set up periodic backups using Task Scheduler. Here's how you can do it:

  1. Open Task Scheduler.
  2. Click on Create Basic Task.
  3. Enter a name and description for the task.
  4. Choose the trigger (e.g., Daily).
  5. Set the time for the trigger.
  6. Choose Start a program as the action.
  7. Browse to the git-sync binary.
  8. Click Finish to create the task.
  9. Right-click on the task and select Run to test it.
  10. Your repositories will now be backed up periodically.

Or you can use Powershell script to run the git-sync binary.

$action = New-ScheduledTaskAction -Execute "path\to\git-sync.exe"
$trigger = New-ScheduledTaskTrigger -Daily -At "12:00AM"
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "GitSyncTask" -Description "Daily Git Sync"

Replace path\to\git-sync.exe with the path to the git-sync binary.