LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Tags used in this thread
Popular LQ Tags , , , , ,

Reply
 
Thread Tools
Old 06-03-2009, 03:45 AM   #1
boomklever
LQ Newbie
 
Registered: Jan 2007
Location: Stuttgart, Germany
Distribution: Debian Etch
Posts: 15
Thanked: 0
rsync - sync files modified within the last 60 days


[Log in to get rid of this advertisement]
Hi

Can anybody tell me how I can synchronise files between two computers in a network that have been modified or created within the last 60 days?

Thanks in advance! :-)
boomklever is offline  
Tag This Post , , , , ,
Reply With Quote
Old 06-03-2009, 03:54 AM   #2
billymayday
Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678
Thanked: 126
something like

find /path -file -mtime -60 -exec rsync {} destination \;
billymayday is offline     Reply With Quote
Thanked by:
Old 06-03-2009, 04:13 AM   #3
boomklever
LQ Newbie
 
Registered: Jan 2007
Location: Stuttgart, Germany
Distribution: Debian Etch
Posts: 15
Thanked: 0

Original Poster
Thanks, I haven't thought of find. That helps. :-)
boomklever is offline     Reply With Quote
Old 06-03-2009, 10:41 AM   #4
boomklever
LQ Newbie
 
Registered: Jan 2007
Location: Stuttgart, Germany
Distribution: Debian Etch
Posts: 15
Thanked: 0

Original Poster
Maybe the way I went to work on the problem is more complicated than it needs to be. Anyway, I worked around it with an extra step, that is done by a perl script I wrote for the purpose. The script, with the help of find, copies all files from a source directory to a destination directory if they're older than a specified amount of days.

Maybe it will come in handy for somebody else, so I post it here:
Code:
#!/usr/bin/perl

use strict;
use warnings;
use File::Path;
use File::Basename;
use File::Spec;
use File::Copy;
use Cwd;
use Getopt::Long;

# make output unbuffered
$| = 1;

my $path     = getcwd;
my $mtime    = 1;
my $dest;
my $verbose  = '';
my $showhelp = '';
my $result   = GetOptions("source=s"  => \$path,
                           "mtime=i"   => \$mtime,
                           "dest=s"    => \$dest,
                           "help"      => \$showhelp,
                           "verbose"   => \$verbose);

# DEBUG
# print "\$path = $path\n\$mtime = $mtime\n\$dest = $dest\n\$showhelp = $showhelp\n\$verbose = $verbose\n";
# exit(0);

my $usage = "Usage: $0 --dest <destination-path>\n\t" .
             "[--source <source-path> | --mtime <mtime> | --verbose] [--help]\n\t" . 
             "Type $0 --help for more information.";
my $help = <<EOHELP;
$0 - Copy file hierarchies selectively
     based on their modification times

Options:
    -s | --source=SourceDir     Source path. Default: pwd
    -m | --mtime                mtime (see man find). Default: 1
    -d | --dest=DestDir         Destination path. Mandatory option.
    -h | --help                 Print this help screen.
    -v | --verbose              Be more verbose. Default: false
EOHELP

if ($showhelp) {
    print $help;
    exit(0);
}
unless ($dest) {
    die "$usage\n";
}

# remove trailing slash from $dest
$dest =~ s/\/$//;
my $find = "find $path -type f -mtime -$mtime";

my @files = `$find`;
my %dirs_created;
foreach (@files) {
    # debug
    print;
    chomp;
    s/^\.\///;

    my ($filename, $directories, $suffix) = fileparse($_);
    my $new_dir = File::Spec->canonpath(File::Spec->catdir($dest, $directories));
    unless (exists $dirs_created{$new_dir}) {
    	$dirs_created{$new_dir} = mkpath($new_dir);
    	print "Created $new_dir\n" if $verbose;
    }
    
    copy($_, File::Spec->catfile($new_dir, "$filename$suffix"));
    print File::Spec->catfile($new_dir, "$filename$suffix") . "\n" if $verbose;
}

exit(0);
boomklever is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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
How to Find and remove 7 days before modified/created files neel.gurjar Linux - Software 2 05-14-2008 09:17 PM
which files have modified in the last few days ? varun_saa Mandriva 6 03-10-2007 11:34 AM
how to list all files modified in last N days sneakyimp Linux - General 3 07-28-2006 01:16 PM
rsync: only backup recently modified files hamish Linux - Software 2 09-05-2005 03:51 PM
Tar files in a dir modified before 7 days in a shell script jayachristina Linux - Newbie 4 05-14-2004 03:49 AM


All times are GMT -5. The time now is 06:55 AM.

Main Menu
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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration