# Using CP to back up home directory

I use the following set of commands to backup my home directory on an HDD in a USB dock. I am using the drive in HDD to backup the home directories in my system and I thought this command would work to both do the initial copy and to later copy files that are new or updated.
[Carl@localhost ~]\$ su

[root@localhost Carl]# cd /home

[root@localhost home]# cp -r -u -v Carl /run/media/Carl/036107cf-8650-421e-a46d-7f0e7df744ca

As I understand the man page for cp this should copy all files from my home directory Carl to directory Carl in the logical volume whose UUID is 036107cf-8650-421e-a46d-7f0e7df744ca. It should not copy a file if the time stamp of the corresponding file in the destination directory is later than that in the source because of the -u option nor should it ask me whether any files are to be replaced Y/N because I have not specified the -i option however as the following extract shows it is so asking.

cp: overwrite '/run/media/Carl/036107cf-8650-421e-a46d-7f0e7df744ca/Carl/.cache/gnome-software/3.24/firmware/firmware.xml.gz.asc'? n

cp: overwrite '/run/media/Carl/036107cf-8650-421e-a46d-7f0e7df744ca/Carl/.cache/gnome-software/3.24/firmware/firmware.xml.gz'? n

cp: overwrite '/run/media/Carl/036107cf-8650-421e-a46d-7f0e7df744ca/Carl/.cache/gnome-software/3.24/ratings/odrs.json'? n

cp: overwrite '/run/media/Carl/036107cf-8650-421e-a46d-7f0e7df744ca/Carl/.cache/gnome-software/3.24/extensions/gnome.json'? n

cp: overwrite '/run/media/Carl/036107cf-8650-421e-a46d-7f0e7df744ca/Carl/.cache/tracker/locale-for-miner-user-guides.txt'? ^C

And since my home directory contains an enormous number of files replying Y or N is impractical especially since I do not know why the command is asking the question.

If cp cannot do what I want is there another command that will?

edit retag close merge delete

use rsync and skip directories like ~/.cache (.thumbnails, ...) when backing up.

( 2018-03-28 13:01:44 -0600 )edit

Sort by » oldest newest most voted

In fedora cp is an alias for cp -i. You can unalias it or call /bin/cp directly. Another command is rsync.

more

I checked with alias and didn't find anything for cp. I also looked in .bashrc and didn't see where I'd changed that command. Where did you get that from? However, I do agree that rsync is probably the best choice.

( 2018-03-28 13:59:44 -0600 )edit

@sideburns you are right, no alias for cp in /etc/bashrc or any of /etc/profile.d/*.sh. Did Fedora ever define those aliases (rm -i too) in the past? I was pretty sure of that.

( 2018-03-28 14:34:36 -0600 )edit

@sideburns Fedora/RHEL does that only for the root account

( 2018-03-28 14:44:29 -0600 )edit

Thank you fcomida, and sideburns, that explains why cp acts as if option -i is specified when I run it under root. The reason that I have to run it under root is that something I have done previously has transferred ownership of some of my files to root.

Is there a command that can list all defined aliases.

In future I will use /bin/cp or rsync.

( 2018-03-30 06:56:49 -0600 )edit

Yes. The command alias when run by itself will do that.

( 2018-03-30 13:07:36 -0600 )edit

A while ago I used: http://rsnapshot.org/ To backup my stuff.

Pretty cool, keeps things as "files" and not encrypted.

more