how to copy files

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

how to copy files

Long Wind
I have a folder in hard drive and a backup of it is made in a USB disk
Now some new files are added to the folder in hard drive
how to make the folder in USB disk the same as in hard drive?

I want a program that can check the two folders
if file size and file name are same, they are regarded as same
if not, update is needed

I have try rsync, but can't find such options

Reply | Threaded
Open this post in threaded view
|

Re: how to copy files

Lisi Reisz
On Sunday 14 May 2017 21:57:35 Long Wind wrote:
> I have a folder in hard drive and a backup of it is made in a USB disk
> Now some new files are added to the folder in hard drive
> how to make the folder in USB disk the same as in hard drive?
>
> I want a program that can check the two folders
> if file size and file name are same, they are regarded as same
> if not, update is needed
>
> I have try rsync, but can't find such options

cp -Rpu /home/. /backup/

will copy only new stiff, but all new stuff.

That is for everything in home.  But you could do the same for one folder or
sub-folder, or one user.

Lisi

Reply | Threaded
Open this post in threaded view
|

Re: how to copy files

Dan Ritter-4
In reply to this post by Long Wind
On Mon, May 15, 2017 at 04:57:35AM +0800, Long Wind wrote:
> I have a folder in hard drive and a backup of it is made in a USB disk
> Now some new files are added to the folder in hard drive
> how to make the folder in USB disk the same as in hard drive?
>
> I want a program that can check the two folders
> if file size and file name are same, they are regarded as same
> if not, update is needed
>
> I have try rsync, but can't find such options

That's the default for rsync.

rsync /path/to/originals/  /path/to/copies/

add -r for recursion into subdirectories
add -v for verbosity
add -a (archive) to keep ownership, groups, and permissions
       identical. That usually needs root privileges.

There are a lot of other options to rsync; you can have
unrecognized files in the destination ignored or deleted.

You can require the contents of all files to match, rather than
just their name and size.

You can have special exclusions and inclusions.

If you need changes on both directories to be reflected in each
other, you want unison instead of rsync.

-dsr-

Reply | Threaded
Open this post in threaded view
|

Re: how to copy files

Long Wind
archive just means that?
Thank Dan Ritter!
l will try it later on.


Reply | Threaded
Open this post in threaded view
|

Re: how to copy files

Dejan Jocic
On 15-05-17, Long Wind wrote:
> archive just means that?
> Thank Dan Ritter!
> l will try it later on.

What you probably want is:

rsync -av /path/to/original/folder /path/to/backup

With this command on your backup rsync will make folder named as folder
in your original path under backup. Notice that there is no need for
those / on the end of paths. Also, you will not need root permission for
your home folder backups with any combination of options for rsync.

Reply | Threaded
Open this post in threaded view
|

Re: how to copy files

Greg Wooledge
In reply to this post by Long Wind
On Mon, May 15, 2017 at 04:57:35AM +0800, Long Wind wrote:
> I have a folder in hard drive and a backup of it is made in a USB disk

What type of file system is on the USB disk?  For backing up files
from a Unix file system, you really want a Unix file system on the
target device, not a FAT32 or NTFS file system.

> Now some new files are added to the folder in hard drive
> how to make the folder in USB disk the same as in hard drive?

cd /source &&
rsync -a . /target

> I want a program that can check the two folders
> if file size and file name are same, they are regarded as same
> if not, update is needed

Wait.  Please explain this part in more detail.

Let's say you have a file named thesis.txt on your hard drive, and it
is 4 bytes long, containing "foo" plus newline.  You copy this to the
USB disk.  Now you edit thesis.txt on the hard drive and change the
content to "bar" plus newline.

Both copies of thesis.txt have the same name and the same size.  But
the copy on the hard drive has a newer timestamp, and it has different
CONTENT.

Are you saying that you want rsync to IGNORE the different timestamp
and the different content, and skip this file, just because it has
the same size as the one on the USB disk?

Why would you want this behavior?

Reply | Threaded
Open this post in threaded view
|

Re: how to copy files

Felix Dietrich
In reply to this post by Dejan Jocic
Dejan Jocic <[hidden email]> writes:

> rsync -av /path/to/original/folder /path/to/backup
>
> Notice that there is no need for those / on the end of paths.

Rsync actually treats a trailing newline on the source path specially;
quoted from the man page:

    A  trailing  slash on the source changes this behavior to avoid
    creating an additional directory level at the destination.  You
    can think of a trailing / on a source as meaning "copy the con‐
    tents of this directory" as opposed to "copy the  directory  by
    name" […]

--
Felix Dietrich

Reply | Threaded
Open this post in threaded view
|

Re: how to copy files

Dejan Jocic
On 20-05-17, Felix Dietrich wrote:

> Dejan Jocic <[hidden email]> writes:
>
> > rsync -av /path/to/original/folder /path/to/backup
> >
> > Notice that there is no need for those / on the end of paths.
>
> Rsync actually treats a trailing newline on the source path specially;
> quoted from the man page:
>
>     A  trailing  slash on the source changes this behavior to avoid
>     creating an additional directory level at the destination.  You
>     can think of a trailing / on a source as meaning "copy the con‐
>     tents of this directory" as opposed to "copy the  directory  by
>     name" […]
>
> --
> Felix Dietrich
>

Yup, I know it. But OP asked for copy of original folder to backup
folder. Not for copy of contents of original folder to some backup
folder, in which case you would use trailing slash. Or at least that is
how I've understood his question.