Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Backing up with "cp" [solved]

If none of the specific sub-forums seem right for your thread, ask here.
Message
Author
uthappam
Posts: 242
Joined: 2010-01-01 17:14
Location: Delhi, India

Backing up with "cp" [solved]

#1 Post by uthappam »

Debian Jessie XFCE. I use this script to periodically back up my home directory to an external drive:

Code: Select all

cp -R -u /home/albert/* /media/albert/"Expansion Drive"/albert/
The configuration files, for example .icedove, are not copied. Can I modify the cp command to include them also?
Last edited by uthappam on 2015-11-12 21:58, edited 2 times in total.

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 133 times

Re: Backing up with "cp"

#2 Post by Head_on_a_Stick »

Don't specify the files:

Code: Select all

cp -R -u /home/albert /media/albert/"Expansion Drive"/albert/
This would be better though:

Code: Select all

rsync -aAXv /home/albert /media/albert/"Expansion Drive"/albert/
This preserves symbolic links, permissions and ownerships, modification times, ACLs and extended attributes.
deadbang

uthappam
Posts: 242
Joined: 2010-01-01 17:14
Location: Delhi, India

Re: Backing up with "cp"

#3 Post by uthappam »

Thank you. I shall give it a go.

uthappam
Posts: 242
Joined: 2010-01-01 17:14
Location: Delhi, India

Re: Backing up with "cp"

#4 Post by uthappam »

It looks like I did not explain myself well enough. I have a full backup on the external drive. What I want is to periodically add files which are not present on the external drive and replace files which have changed since the last backup. I ran the rsync command you gave and it copied all the files -- which would not have happened with cp -u. It was a waste of time. Also, I do not understand why -r was missing from the command you gave me.

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 133 times

Re: Backing up with "cp"

#5 Post by Head_on_a_Stick »

uthappam wrote:I ran the rsync command you gave and it copied all the files -- which would not have happened with cp -u. It was a waste of time.
That's not what happens when I use rsync(1) but I have never tried using `cp -u` beforehand.

If you try running rsync(1) again I am confident it will only copy over the files that are different (use "--delete" to remove files no longer present in $SOURCE).

I have no idea what you mean by "-r" being missing.

"-R" and "-r" and exactly equivalent -- see cp(1)
deadbang

uthappam
Posts: 242
Joined: 2010-01-01 17:14
Location: Delhi, India

Re: Backing up with "cp"

#6 Post by uthappam »

What the rsync command did was copy over a second complete directory tree. I have deleted it and am going back to cp. There was no r switch in the rsync command you gave.

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 133 times

Re: Backing up with "cp"

#7 Post by Head_on_a_Stick »

uthappam wrote:What the rsync command did was copy over a second complete directory tree
Watch those trailing slashes if you want to define the folder structure ;)
uthappam wrote:There was no r switch in the rsync command you gave
Yes there was, read the man page...
deadbang

uthappam
Posts: 242
Joined: 2010-01-01 17:14
Location: Delhi, India

Re: Backing up with "cp"

#8 Post by uthappam »

This old fellow is now confused and will start afresh. What I need is a script which I can run periodically to copy new and changed files (including hidden files) to my external drive (which now contains only the files which Seagate put there). Source is /home/albert.

User avatar
RU55EL
Posts: 546
Joined: 2014-04-07 03:42
Location: /home/russel

Re: Backing up with "cp"

#9 Post by RU55EL »

When you run rsync again (using the same destination) it will only copy the differences.

I use rsync to backup my work files on my notebook computer. I simply added an alias to the .bash_aliases file in the home directory.

Code: Select all

alias work.backup='sudo rsync -azhv --delete /home/russel/Documents/work_files/ /media/russel/Backup_Drive/work.files.backup'
That way, when I get home I just plug in the backup external drive and type work.backup at the command line.

The first time that I ran the command to back up to my external hard drive it took a while because I have about 27GB of data. But, after that it only copies any changes that you make. So, subsequent backups only take seconds.

Note: By adding --delete to the command, it will remove files from the backup drive if I have deleted them from my work files on the notebook.

uthappam
Posts: 242
Joined: 2010-01-01 17:14
Location: Delhi, India

Re: Backing up with "cp"

#10 Post by uthappam »

Thank you, Russel. I shall study the rsync command and try to figure out this .bash_aliases business. I have thousands of photos, so the first run will take a long while. Is your limit 55 miles an hour or that many kilobytes a second?

User avatar
RU55EL
Posts: 546
Joined: 2014-04-07 03:42
Location: /home/russel

Re: Backing up with "cp"

#11 Post by RU55EL »

alias is a very useful command.

If you type ll at the command line you typically get:

Code: Select all

bash: ll: command not found
If you then type:

Code: Select all

alias ll=ls -l
then type ll at the command line you get the same result as if you typed

Code: Select all

ls -l
But, as soon as you reboot, or close the terminal window and open a new one the alias command you created is gone. If you add the alias command to the .bash_aliases file in your home directory the command will always be available. If you forget which alias commands you have defined, just type

Code: Select all

alias
at the command line to see a listing of aliased commands.

Note: I just completed and rsync backup of my work data.

Code: Select all

sent 3.02M bytes  received 636 bytes  1.21M bytes/sec
total size is 27.51G  speedup is 9,101.06

uthappam
Posts: 242
Joined: 2010-01-01 17:14
Location: Delhi, India

Re: Backing up with "cp" [solved, sort of]

#12 Post by uthappam »

Thank you, Russel. I have decided to stay with that with which I am comfortable. For routine updates I shall use the script I gave in my first post, with the hidden (dot) files being copied over with a file browser less frequently.

User avatar
dasein
Posts: 7680
Joined: 2011-03-04 01:06
Location: Terra Incantationum

Re: Backing up with "cp"

#13 Post by dasein »

uthappam wrote:What the rsync command did was copy over a second complete directory tree.
If that's what "rsync did," it's because that's what you told rsync to do.

HoaS is entirely correct: rsync is exactly the right tool for exactly the job you're trying to accomplish.

My suggestion to you is this: experiment a little with some small test runs in rsync until you get comfortable with its syntax and understand its operation. Once you get the hang of it, you'll see that it's the perfect tool for this job.

Or if CLI just isn't your thing, have a look at grsync.

uthappam
Posts: 242
Joined: 2010-01-01 17:14
Location: Delhi, India

Re: Backing up with "cp" [solved, sort of]

#14 Post by uthappam »

I told rsync to do what it did because I was told to tell it what I told it.

User avatar
dasein
Posts: 7680
Joined: 2011-03-04 01:06
Location: Terra Incantationum

Re: Backing up with "cp" [solved, sort of]

#15 Post by dasein »

My sincere apologies for trying to help you. I promise not to repeat the mistake.

uthappam
Posts: 242
Joined: 2010-01-01 17:14
Location: Delhi, India

Re: Backing up with "cp" [solved, sort of]

#16 Post by uthappam »

What what you said makes sense -- but you too accuse me of doing the wrong thing, failing to see that I did what I was told to do .

User avatar
RU55EL
Posts: 546
Joined: 2014-04-07 03:42
Location: /home/russel

Re: Backing up with "cp" [solved, sort of]

#17 Post by RU55EL »

This is not about blame...it is about learning!

I suggest you follow dasein's excellent suggestions, experiment and learn how to use rsync. It is the perfect program for backing up files, including hidden files.

uthappam
Posts: 242
Joined: 2010-01-01 17:14
Location: Delhi, India

Re: Backing up with "cp" [solved, sort of]

#18 Post by uthappam »

Russel, I've learnt not to follow advice without at least trying to see that it won't make me waste time. And perhaps you will agree that nothing is perfect for everyone. Thank you, wizard-with-many-zeroes. I shall stay with that with which I am comfortable. All old dogs are not keen to learn new tricks.

uthappam
Posts: 242
Joined: 2010-01-01 17:14
Location: Delhi, India

Re: Backing up with "cp" [solved, sort of]

#19 Post by uthappam »

wizard10000, I shall appreciate help with a single command which can do what I want. Will

Code: Select all

cp -R -u /home/albert /media/albert/"Expansion Drive"/albert/
do the job? There is no /* after /home/albert, the source.

Alternatively, will

Code: Select all

rsync -av /home/albert /media/albert/"Expansion Drive"/albert/
recursively freshen files, including hidden files? The switches are different from the ones I used earlier, and there is no slash after source. Each alternative has a slash after destination, which I think should not cause trouble. I'm afraid I could not properly understand the explanation in the link you gave.

The directory "albert" is at the top level in my external hard drive -- and I do not wish again to create another complete "albert" under it.

uthappam
Posts: 242
Joined: 2010-01-01 17:14
Location: Delhi, India

Re: Backing up with "cp" [solved, sort of]

#20 Post by uthappam »

Thank you. I shall delete the "albert" tree on my external drive and run

Code: Select all

rsync -av /home/albert "/media/albert/Expansion Drive"
I notice that you have -u in your script but not in the command you wrote for me. Any reason not to use -uav?

Post Reply