LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-21-2009, 10:04 AM   #1
jsteel
Member
 
Registered: Mar 2007
Location: England
Distribution: Arch
Posts: 392

Rep: Reputation: 34
CP Question RE: Checking if file is smaller than destination


Hi,

I'm currently using cp to copy files over night to a backup server using:

cp -pru /mnt/server-01/documents /home/backups/

This only copies files if they are newer than the destination (or if the destination file doesn't exist). What this won't protect me against is if someone overwrites a file with a blank one. The blank document will be newer than the old so it will overwrite the backup copy.

Is there a way to check if the file size is smaller, and if so create a different copy for example:

/home/backups/documents/me/quotes/computers.odt (100kb)
/home/backups/documents/me/quotes/computers-2.odt (94kb)

I hope that makes sense, thanks!

P.S. If cp cannot do this, what can?
 
Old 10-21-2009, 09:08 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
You could use the -size option of the find cmd http://www.computerhope.com/unix/ufind.htm to check the size, passing in the size of the src file.
Might be overkill for each file.
The easiest might be to generate sorted lists of src & dest dirs, then compare same named file sizes (is use ls -l).
Basically, I think you need a short script.
 
Old 10-22-2009, 04:49 AM   #3
jsteel
Member
 
Registered: Mar 2007
Location: England
Distribution: Arch
Posts: 392

Original Poster
Rep: Reputation: 34
Thanks for your suggestions. As there is a huge amount of data, running a find may take far too long.

I found that with cp you can specify the backup switch (-b) which creates a backup of the old file. For example:

/home/backups/documents/me/quotes/computers.odt~ (100kb)
/home/backups/documents/me/quotes/computers.odt (94kb) (newer)

The older of the two files has the ~ symbol at the end of the file name. These are always the two newest files (the backup file gets updated at the same time).

I think this is the easiest method, but it would be nice if it was a bit more flexible (for example to store 3 copies of the file rather than two. I know you can have it number these files, but the hard drive will fill up very quickly as there's no limit to the number it increases to!).
 
Old 10-22-2009, 07:37 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Like a I said, a simple/quick soln is just to ls -l src and destn dirs, piped through sort, and compare file sizes.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about AIDE or other file integrity checking software twk Linux - Security 5 05-13-2008 07:21 PM
Free disk space in '/' getting smaller and smaller. simjii SUSE / openSUSE 5 12-16-2005 11:24 AM
when creating a *.iso file, how to make the file size smaller? minm Linux - Newbie 8 12-26-2004 09:58 PM
How do I redirect something to a file without it overwriting the destination file??? nikold01 Linux - General 8 09-09-2004 02:30 PM
The big question, and a few smaller ones... redkazan Linux - Newbie 7 01-07-2004 02:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration