Noidea Noidea - 1 year ago 88
Bash Question

Linux backup files command

I had a problem with my Ubuntu install. I was able to boot from liveCD and connect an external hard drive. I want to backup my files now.

I tried

cp -r /home destination
, but I get problem with spaces in filenames, symlinks, errors "Cannot create fifo: Operation not permitted" "Permission denied" "Invalid argument" and plenty more. What is the best way to do it? Will
cp -a
fix these issues or should I do something more clever?

I found out that
doesn't have problems with filenames. But it doesn't copy .so and .a files. Also it is running extremely slow comparing to


I followed the advice of John Bollinger and created an archive, because my external drive wasn't ext4 formatted.

From a liveCD
refers to liveCD home, so one has to use:

tar -c -z -f /my/backup/disk/home.tar.gz -C / media/ubuntu/longDeviceName/home

Despite sudo, I still received some "Cannot open: Permission denied" and "socket ignored" errors creating a tar for several .png files in .cache/software-center/icons/blabla. I wonder whether it is normal.

Answer Source

If you do not want to reformat your backup disk with a filesystem that has enough capabilities to represent all of the attributes of your files (e.g. ext4) then preserving them across the backup requires putting them into some sort of container. The traditional container for this sort of thing is a [compressed] tarball. You might therefore try

tar -c -z -f /my/backup/disk/home.tar.gz -C / home

You would recover the contents of that tarball via

tar -x -z -f /my/backup/disk/home.tar.gz -C /

Either or both might need to be run with privilege, obtained by being root or by using sudo.

That will handle symlinks, executable files, and any filename just fine, but it may still have trouble if the data you are trying to back up include any special files, such as device nodes or FIFOs. In that event, you may simply need to remove such files first, and recreate them after restoring the other files. You can identify such files via find:

find /home -not -type f -not -type d -not -type l
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download