Earlier I used FreeFileSync to backup the updated files and folders to an external HDD, but I was looking for a better and quicker solution for backups and finally found one. I have used rsync
in the past for file transfer but never really thought about this use case of using it to backup laptop’s data to an external drive.
I just run the rsynchdd
terminal command, and all updated files/folders and backed up within seconds.
Before I explain my process, currently, I’m on Macbook Air M2 and using the Seagate Expansion 2TB External HDD as the external backup drive.
Now, let’s go through the steps one-by-one:
Step 1: Install rsync
on your computer
The easiest way to install rsync
on a Mac computer is via Homebrew by running the following command.
brew install rsync
But you can visit their official website to learn more about the installation process.
Step 2: Get the exact name of your external drive
You can run the below terminal command to know the exact name, but make sure that your drive is connected to the computer before running the command.
ls /Volumes
Copy the exact name of the drive and move to the next step.
Step 3: Decide which folders you want to back up
I back up the entire Users/deepak
folder except a few folders in it that I exclude by using the --exclude
flag, so now my final command becomes like this.
rsync -avh --progress --exclude 'Library' --exclude '.*' --exclude 'Applications' /Users/<USER_NAME>/ /Volumes/<EXTERNAL_DRIVE>/<FOLDER>
Here, you will have to replace <USER_NAME>
with your computer’s user name, then replace <EXTERNAL_DRIVE>
with the name of your external drive that you get from the step #2, and then replace <FOLDER>
with the name of the folder that you want to keep in the external drive.
Test the above command and see if those files are being copied in the external HDD or not, if it works then we’re ready to move to the next steps.
You may also need to provide your Terminal app the Full Disk Access by going into the Privacy and Security section in the System Settings app, as you can see in the above screenshot.
Step 4: Create an alias
Now, trying to type or even copy-paste the command from the step #3 every time is a difficult task. So… we’re going to create an alias.
If you use the zsh (default on newer macOS versions), then type the following terminal command:
nano ~/.zshrc
Add the below line at the very end of the file with the alias you want to keep. For example, if I keep rsynchdd
then I would write:
alias rsynchdd="rsync -avh --progress --exclude 'Library' --exclude '.*' --exclude 'Applications' /Users/<USER_NAME>/ /Volumes/<EXTERNAL_DRIVE>/<FOLDER>"
Make sure to replace the variables in the above command as explained in the step #3. After that, save and exit the nano editor by pressing Ctrl + X
, then Y
, and then Enter
.
Reload your shell by running the following command:
source ~/.zshrc
And now you’re done.
rsynchdd
Whenever you just type the alias name, i.e. rsynchdd
in my case, and press Enter, it’s going to sync all the changes immediately. You just have to connect your HDD to your computer before running the command.
Further, if you want to back up files to a remote storage like Hetzner Storage Box via rsync then I have written another post about this.
That’s it.
Leave a Reply