Solved

how to copy only updated files

Posted on 2001-06-13
9
388 Views
Last Modified: 2010-04-21
i am new to linux . i want to copy the files from /home to /usr/backup but the condition being that only the files which are modified in the last week in the /home only to be copied to /usr/backup directory. could someone suggest how to do this.
thanks for the help

Sudarshan
0
Comment
Question by:sudarshankr
  • 4
  • 3
  • 2
9 Comments
 
LVL 5

Expert Comment

by:garboua
ID: 6188365
you can use the find command
find /home -atime -7 -exec cp -p {} /usr/backup \;
the -atime option specified number of days and you can even use the +N -N to copy files changed within a range of time.  cp -p will copy the files and keep their permission intact.
use the don't forget the "\;" at end of command.
0
 
LVL 5

Expert Comment

by:garboua
ID: 6188372
Oh there is a space between the } and /usr/backup.
0
 

Expert Comment

by:sudarshan1975
ID: 6189468
i will try this and get back to u if i have any problems

thank u.

Sudarshan
0
 

Expert Comment

by:sudarshan1975
ID: 6189476
could u please expand the usage of +N and -N in the copy usage.

Thankk you


Sudarshan
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Expert Comment

by:sudarshan1975
ID: 6189587
i have tried the option it works fine for the directories,
but for files under directories even if it is modified some time before 7 days also it is copying.

eg:
I have  a dir test and files file.1 file.2 and file.3
if file.2 and file.3 is modified as on feb 26th bu the dir test is modified as jun14 even then while copying it is coyoing the file.3 also. How should i restrict that


Thanks for the reply

Sudarshan
0
 
LVL 5

Expert Comment

by:garboua
ID: 6191733
do a man on "find"
"find ./  -type d " will look for directories
'find ./ -name "*" ' will find all files
the rule for for using the plus and minus:::::::::::::
when you do -atime and give it a minus "-"  it start at present time.  so -atime -7 will give you all files accessed past 7 days.  OKAY, now, -atime +7 will give you files that are OLDER than 7 days, meaning it will ignore every thing you accessed the past 7 days.
do if you do a find -name "*" -atime +45 will result in "your case" file 2 and file3
if you only want to copy i assume file1,
find /path -name "*" -atime -14 -exec cp -p -f {} \;
this will copy all from jun 1 until now.
0
 

Author Comment

by:sudarshankr
ID: 6195010
i am using the same with -mtime since i wish to backup the
files which are changed since last week. HOpe that is working fine . Thank u very much for the assistance.

how to copy the files along with the directory contents.
If i am asking some unusual question please let me know

Thanks

Bye

Sudarshan
     
 
0
 
LVL 5

Accepted Solution

by:
garboua earned 70 total points
ID: 6195231
there isn't such a thing as an unusual question. this is a knowledge share extravag... so you should always ask and try stuff.  
you know there are better way of backing up your system or directories without going through all this stuff, and you can even automate it so it will run as part of system crons, crons==scheduled task.
as i was saying, there are plenty stuff out there.  one tool most people use, and will come in very handy, is "tar"
tar works like winzip, but more flex and powerfull.  You can give it a path to say /home/suff and run it every week, it will only update those files that have been changed.  tar produces a , DAHHH, tar file and usually you give it .tar
You might know this, but the first thing you do, to get the hang of this linux, nd even unix, thing is get familiar with the "man pages"
if you type " man tar"  you will get almost everything you need about tar.  man pages works for all linux commands and even user deffined app.   so if you have a command on you system, there is probably a man file for it.
that being said check the online man page for tar.
http://unixhelp.ed.ac.uk/CGI/man-cgi?tar

this is a step by step documentation that will help you understn and use tar will all kind of options how-to.
http://www.gnu.org/manual/tar/html_chapter/tar_toc.html

understan cron it will come handy to administer your box.


0
 

Author Comment

by:sudarshankr
ID: 6195405
thanks for the help and i will surely get back to u if i face any problem with the tar for more help

thanks a lot

Regards

Sudarshan

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CentOS 6.6 Port opening question 1 136
getting permission denied error on stopping a service 1 37
Linux 10 106
Cron jobs 12 121
Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now