Backing up to an external hard drive using terminal commands
I would go with rsync
, as it only copies files changed since the last run, which makes the second and subsequent backups faster.
Assuming your username Freddy Frog
and your external HDD is called My External Drive
, you can do this:
rsync -av "/Users/Freddy Frog" "/Volumes/My External Drive"
source to share
cp -R / Path to folder / Path to external HDD
This is to copy the folder from the "Folder Path" folder to the external hard drive
If you want to do it as a repeating command, follow these steps:
- Open a text editor and write:
- Save it as Backup.plist
- Now go to / Library / LaunchDaemons and put the file in the folder
- Restart your computer.
Every day at 15:00 the / Path -to-folder will be copied to the external hard drive (if Mac is running at this time)
And yes of course you need to change the code I gave you for the .plist file
source to share
backup to a single (optionally compressed) disk image file that can be restored using Apples Disk Utility with hdiutil
sudo hdiutil create dst_image.dmg -format UDZO -nocrossdev -srcdir src_directory
OSXDaily also provided examples in 2009: for ditto , rsync and asr
sudo ditto -X src_directory dst_directory
sudo rsync -xrlptgoEv --progress --delete src_directory dst_directory
sudo asr -source src_directory -target dst_directory -erase -noprompt
source to share