Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
on RHEL5 i have a directory files (as my Source)
/tenant/tent1/trans/t*.txt
/tenant/tent2/trans/t*.txt
/tenant/tent3/trans/t*.txt
:
/tenant/tentN/trans/t*.txt
on remote SOLARIS i have the same directories(as my target Destination)
The things to do
- Automatically create backup copies to another folder (e.g /backup/<same directory tree>
- Script only process directories that have files inside
- Create log files containing list of files to be copied.
- Backup the files from source to destination
- source files must be deleted automatically
- Report files that are not move into a log file
- The log file should have a file name derive on system time and date (e.g. 2008-01-09_05:30:10pm-sent.txt)
rsync is a very good program for backing up/mirroring a directory tree of files from one machine to another machine, and for keeping the two machines "in sync."
Yes, rsync is the best that I have seen works for stuff like this.
You can configure it to automatically login from one machine to another using authentication keys to identify. Search the web for the steps to do this.
You can set up a cron job and get your nightly backup's done this way.
I have tried rsync together with ssh-pass to automate login.
Below is my script (some codes are long method =) coz i dont have much experience scripting). I hope someone can help optimize.
# Begin Code
#! /usr/bin/perl
my $logdir = "/application/logfiles/filesync/";
my $maindir="/tenant/";
my $backupdir = "/data/tenant/";
my $fbdir = "bk2";
my $dirlistfile = "dirlist.txt";
my $dfsdir = "dfs";
my $userid = "poller";
my $password = "cyanide235";
# Sub Routine Sections
sub trim($)
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
};
# Left trim function to remove leading whitespace
sub ltrim($)
{
my $string = shift;
$string =~ s/^\s+//;
return $string;
};
# Right trim function to remove trailing whitespace
sub rtrim($)
{
my $string = shift;
$string =~ s/\s+$//;
return $string;
};
# Step 2 do an ls | wc -l for each directory on the list extracting thos directory with files
open(fdirlist,$dirlistfile) || die ("Error: Cannot find Tenants File");
if ( -d "$maindir")
{
}
else
{
print "Directory $maindir does not exist.Halting\n";
exit;
}
my $dfscnt=0;
my $tcmd = "echo \"\# Filtered \`date\`\" \> tosync.txt";
system($tcmd);
wait;
while ($line = <fdirlist>)
{
if ( $line=~/^\;/ ) {next;}
@row=split(/\|/, $line);
my $tenant_no = trim($row[0]);
my $shop_dir = trim($row[1]);
my $cat = trim($row[2]);
my $rsyncdir="";
my $lsdir = $maindir . $shop_dir . "\/trans\/";
if ($cat eq "DFS")
{
if ($dfscnt = 1)
{
next;
}
else
{
$lsdir = $maindir . $dfsdir . "\/trans\/";
$rsyncdir= $dfsdir . "\/trans\/";
}
}
# Step 3 Rsync the files indicated on the tosync.txt
# for future rsync -> my $rsynccmd = "rsync \-avpWzhtog \-\-include\-from\=tosync\.txt \-\-progress \-\-verbose root\@193\.41\.134\.197\:\/tenant\/ ";
open(fdirfile,"tosync.txt") || die ("Error: Cannot find Tenants File");
while ($dline = <fdirfile>)
{
if ( $dline=~/^\;/ ) {next;}
if ( $dline=~/^\#/ ) {next;}
@drow=split(/\|/, $dline);
my $rs_dir = $drow[0];
my $syncdt = `date +%F_%T`;
chomp $syncdt;
my $rsynccmd = "sshpass -p $password rsync \-avpWzhtog \-\-remove\-sent\-files $rs_dir $userid\@193\.41\.134\.197\:$rs_dir 1\>$logdir" . "$syncdt\-sent.log 2\>$logdir" . "$syncdt\-sent\.err";
print $rsynccmd . "\n";
system($rsynccmd);
wait;
}
# End of Step 3
# End Code
But the problem is that im having difficulty on the proper usage of the --include-from=File parameter of rsync thats why i parsed the file manually passing those directory name as parameter for rsync.
and 2nd thing im a little confused on how to use the same directory path programatically in rsync.
e.g. rsync -avz --include-from=tosync.txt /tenant/ 193.41.134.197:?<same path as my source>
in this case. i only want to copy all t*.* from the directory /tenant/abr_111_01/trans/ to the remote directory 193.41.134.197:/tenant/abr_111_01/trans/ and the rest is ignore. so how do i acomplish this using the code above and rsync?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.