'Backup to external HDD with terminal commands
Is there any terminal command that allows me to backup all my files to an external HDD. My OSX update failed so I need to backup my files some how, ASAP!
Solution 1:[1]
I would go with rsync as it only copies files changed since the last time you ran it, making it quicker on second and subsequent backups.
Assuming your username is Freddy Frog and your external HDD is called My External Drive, you could do this:
rsync -av "/Users/Freddy Frog" "/Volumes/My External Drive"
Solution 2:[2]
cp -R /Path-to-folder /Path-to-external-HDD
This wil copy the folder from (Path-to-folder) to the external HDD
If you want to make this an recurring command, the are a few steps to be made:
- Open texteditor and write:
- Save it as Backup.plist
- Now navigate to /Library/LaunchDaemons and place the file in the folder
- Restart your machine
Every day at 15:00 the folder of /Path-to-folder will be copied to the external HDD (if the mac is running at that time)
And yes, ofcourse you need to modify the code I gave you for the .plist file
Solution 3:[3]
backup to a single (optionally compressed) disk image file that can be restored using Appleās Disk Utility software with hdiutil
sudo hdiutil create dst_image.dmg -format UDZO -nocrossdev -srcdir src_directory
OSXDaily also provided examples in 2009: for ditto, rsync, & 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
Solution 4:[4]
With new macs which use AFS (Apple file system), do:
diskutil list
to get a list of disks and their identifiers. Then, unlock your disk with:
diskutil apfs unlock <disk_identifier>
and provide your password. You should now view your disk under /Volumes/. For me, the disk of interest was Macintosh HD - Data.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Roy |
| Solution 3 | |
| Solution 4 | Tomasz Bartkowiak |
