Backing up with "cp" [solved]

If none of the more specific forums is the right place to ask

Backing up with "cp" [solved]

Postby uthappam » 2015-11-09 17:46

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.
uthappam
 
Posts: 242
Joined: 2010-01-01 17:14
Location: Delhi, India

Re: Backing up with "cp"

Postby Head_on_a_Stick » 2015-11-09 18:21

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.
Black Lives Matter

Debian buster-backports ISO image: for new hardware support
User avatar
Head_on_a_Stick
 
Posts: 12486
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Backing up with "cp"

Postby uthappam » 2015-11-09 23:04

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"

Postby uthappam » 2015-11-10 20:12

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.
uthappam
 
Posts: 242
Joined: 2010-01-01 17:14
Location: Delhi, India

Re: Backing up with "cp"

Postby Head_on_a_Stick » 2015-11-10 20:19

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)
Black Lives Matter

Debian buster-backports ISO image: for new hardware support
User avatar
Head_on_a_Stick
 
Posts: 12486
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Backing up with "cp"

Postby uthappam » 2015-11-10 20:31

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.
uthappam
 
Posts: 242
Joined: 2010-01-01 17:14
Location: Delhi, India

Re: Backing up with "cp"

Postby Head_on_a_Stick » 2015-11-10 20:41

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...
Black Lives Matter

Debian buster-backports ISO image: for new hardware support
User avatar
Head_on_a_Stick
 
Posts: 12486
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Backing up with "cp"

Postby uthappam » 2015-11-10 21:48

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.
uthappam
 
Posts: 242
Joined: 2010-01-01 17:14
Location: Delhi, India

Re: Backing up with "cp"

Postby RU55EL » 2015-11-10 23:02

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.
User avatar
RU55EL
 
Posts: 474
Joined: 2014-04-07 03:42
Location: /home/russel

Re: Backing up with "cp"

Postby uthappam » 2015-11-10 23:17

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?
uthappam
 
Posts: 242
Joined: 2010-01-01 17:14
Location: Delhi, India

Re: Backing up with "cp"

Postby RU55EL » 2015-11-11 02:27

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
User avatar
RU55EL
 
Posts: 474
Joined: 2014-04-07 03:42
Location: /home/russel

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

Postby uthappam » 2015-11-11 07:39

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.
uthappam
 
Posts: 242
Joined: 2010-01-01 17:14
Location: Delhi, India

Re: Backing up with "cp"

Postby dasein » 2015-11-11 15:51

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.
User avatar
dasein
 
Posts: 7775
Joined: 2011-03-04 01:06
Location: Terra Incantationum

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

Postby uthappam » 2015-11-11 16:03

I told rsync to do what it did because I was told to tell it what I told it.
uthappam
 
Posts: 242
Joined: 2010-01-01 17:14
Location: Delhi, India

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

Postby dasein » 2015-11-11 16:05

My sincere apologies for trying to help you. I promise not to repeat the mistake.
User avatar
dasein
 
Posts: 7775
Joined: 2011-03-04 01:06
Location: Terra Incantationum

Next

Return to General Questions

Who is online

Users browsing this forum: No registered users and 7 guests

fashionable