Backup Source Code

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Backup Source Code Sat Sep 09, 2023 10:52 am • by bloudraak
Hello,

I'm a software engineer with a bit of source code on my machine mostly versioned in git. I'd like to back them up from time to time, since I have made stupid mistakes which resulted in loss of code. For example, I rebased the wrong branch being tired, and screwed up my local branch, losing code. Fortunally, I made a copy of it the previous day, and could quickly recover.

When doing it manually, the process is something like this:

  • Create a Backup Directory ~/Backups/YYYY/MM/DD
  • Find all .git directories. They are usually in subdirectories under ~/Developer, such as ~/Developer/wernerstrydom/website/.git
  • For each .git archive the parent directory, excluding certain directories (.terraform, .terraform.d, dist).
  • Copy the archive to the Backup directory, using the relative path to ~/Developer. This is because some folder names may be identical, such as ~/Developer/wernerstrydom/website and ~/Developer/bloudraak/website. These are actually distinct repositories in different GitHub organizations.

I really only want to run it on git repositories that have changed since the last time the process was run.

Would this be possible with Hazel?

Thanks,
Werner
bloudraak
 
Posts: 1
Joined: Sat May 11, 2013 4:13 pm

Re: Backup Source Code Mon Sep 11, 2023 8:59 am • by Mr_Noodle
Personally, I'd suggest using Time Machine for this but if you insist on using Hazel, it might be doable depending on specific details.

For one, first look in the manual on how to sync one folder to another. It's a one-way sync but it shows you the basic structure of the rule. Instead of using the sync action, you probably want to do a copy. Using the relative path may be possible using Sort into subfolder and specifying the correct folder to monitor.

The problem with this is that it copies the whole directory. There's no way to filter out certain subdirectories.

If you want to do that, then you may, instead, need to have Hazel go into subfolders (look it up in the manual) and copy the individual files, copying over the folder structure as well. This is a bit trickier in terms of specifying the destination. You might need to copy it to a temp location, then move that whole directory tree to the final location.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support