13

I have researched this for hours. In Single User Mode, I used:

cp -Rpvn /* /Volumes/MyBackup

My external USB is mounted on /Volumes/MyBackup

The issue however is that after 24hrs it still has not stopped copying 300GB of data to an external USB drive. I think it is having issues with symbolic links such as the /Volumes/MacHD volume also having a /Volumes/MacHD and /Volumes/MyBackup I am not sure about this however.

How do I copy a Mac volume using cp? Is cp -Rpvn /* /Volumes/MyBackup correct?

  • 2
    You use cp like this, but it is not the correct tool for the job. You need rsync for this. – CousinCocaine Apr 24 '15 at 22:49
  • 1
    Do you have the possibility to run your mac in target disk mode? Or perhaps just pop out the HD? – CousinCocaine Apr 24 '15 at 22:49
  • I am unable to do target mode since I dont have a second mac. I was hoping for a less risky option than taking out the drive. – ermSO Apr 24 '15 at 22:54
  • rsync is probably your best option here, though I think you can also use dd to make a byte for byte copy of your Mac's HDD. – thibmaek Apr 25 '15 at 9:56
  • 1
    dd is the way to go for sector-by-sector backups, which seems like what you're doing here (but be very careful with it, to make sure the thing you're overwriting is actually the thing you want to overwrite). rsync is the way to go to do complicated or large copy operations. cp is great for individual files, but isn't good for large-scale operations. – cpast Apr 25 '15 at 17:41
24

Use rsync for this purpose since cp cannot faithfully reproduce all the files that exist on OS X. The benefits of rsync over ditto and cp are:

  • interrupted transfers can restart easily with very little cost.
  • restarts even resume part way through a large file.
  • file exclusion and --dry-run allow easy testing and iterative thinning.

The simplest way to use rsync and preserve most things (permissions, symlinks, edit dates, etc) is to use the -a or --archive flag to archive. To see your progress use -P or --progress

Rsync works as:

rsync options source destination

In your case I would recommend the following:

rsync --archive --verbose --one-file-system --human-readable --progress /from/ /to

Or in short:

rsync -avxhP /from/ /to

Mind the lack of trailing slash in the /to location.

see comments for more useful flags

  • 6
    You also want the -x flag, to avoid traversing to mounted disks that aren't on the same volume. – Kent Apr 25 '15 at 12:16
  • kudo's for bmike for making this post a lot more readable. – CousinCocaine Apr 30 '15 at 19:13
  • 2
    -P is actually equivalent to both --progress and --partial combined. See the man page. – kirb May 1 '15 at 8:59
  • 1
    I'd skip --compress (it's only useful for network transfers), and add -E (preserve extended attributes and resource forks). – Gordon Davisson May 2 '15 at 5:16
5

If you want to make a faithful copy of the filesystem contents, avoid using cp. Instead, use the ditto(1) command, which preserves hard links, file permissions, resource forks, and HFS metadata. Unlike cp, ditto is meant to preserve as much of that information as possible by default.

It's just a matter of running sudo ditto src dest.

  • Correct me if I am wrong, but I am pretty sure cp was updated to copy file metadata in 10.4. – NobodyNada Apr 25 '15 at 14:57
  • It was, but ditto is still a better option. – juandesant Apr 25 '15 at 21:47
  • 1
    And rsync is the best option. – CousinCocaine Apr 26 '15 at 7:39
2

You forgot to make an exclude-files list, and are likely copying things that can't / shouldn't be copied, including bottomless files like /dev/random.

While cp can do the job, there are better tools. Rsync is one, Carbon Copy Cloner or SuperDuper is another. To use a kitchen analogy, you are using a knife to open a can. Rsync is a can opener, Carbon Copy Cloner is an electric can opener. I use rsync regularly, but the settings needed to copy a running operating system are sufficiently complex I've never bothered to do it all myself.

 cp -Rpvn /* /Volumes/MyBackup 

It looks like all you want to do is make a backup. Your Mac includes Time Machine expressly for this purpose. Open System Preferences -> Time Machine, choose the external disk, turn it on and then leave it alone. It works very well and requires under a minute of your time.

  • I am unable to access a GUI. All I am able to get working is Single User Mode, so time CCC, superduper and time machine are not options. What settings would you use with rsync? Ideally i would like a bootable copy. I could not get asr to work. – ermSO Apr 25 '15 at 0:40
  • 1
    @ermSO Since you obviously have an external drive, install a new OS on the external and then boot from it. All current Macs can boot from either firewire or USB. You can then make a decent backup of your user files and then repair your internal drive. I usually do a complete erase in these cases, eliminating any residual directory problems. – paul Apr 25 '15 at 13:08
  • dd will do sector-by-sector copies on the command line, and is a good choice for copying an entire volume onto another entire volume while erasing the whole second volume. – cpast Apr 25 '15 at 17:43
  • Are you sure that you want the -R option? That means that if you have symbolic links to a single folder in several places, you will be duplicating content. That might explain the time is taking. If you use ditto instead, you'll get what you want with the default settings. – juandesant Apr 25 '15 at 21:54
  • 1
    @juandesant it's his command, not mine. i wouldn't use cp at all. – paul Apr 26 '15 at 7:32
0

You can create a time Time Machine backup from the command line with tmutil, the Time Machine utility. You can set a destination then order a manual backup.

To set the Time Machine backup volume:

sudo tmutil setdestination /Volumes/MyBackup

Then start the backup:

tmutil startbackup --auto

The --auto flag will try to treat it as an ordinary time scheduled backup.

Once you have your Time Machine backup, you can then re-install OS X on your Mac, then import all of your files from the Time Machine backup.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .