Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )



Advanced DNS Management
New ZoneEdit. New Managment.

FREE DNS Is Back

Sign Up Now
 
Reply to this topicStart new topic
> Directory Tree Replication, mirror a whole directory tree
end-user
post Dec 10 2004, 04:06 PM
Post #1


Whats this Lie-nix Thing?
*

Group: Members
Posts: 7
Joined: 8-November 04
Member No.: 4,132



Does anyone know a way for me to replicate a directory tree? I have 'path a' that I want to mirror over to 'path b'. Later, stuff changes in 'path a'; I want to detect those changes and perform them over in 'path b'. Specifically, I want to copy (overwrite) new and changed files, but I also want to perform deletions (preferably first, so there's more space for new additions).

Any suggestions?
Go to the top of the page
 
+Quote Post
Hemant
post Dec 11 2004, 04:26 PM
Post #2


RMS is my Hero
******

Group: Support Specialist
Posts: 782
Joined: 6-October 02
From: Trichy,INDIA
Member No.: 29



Sorry but i didn't get the question.So i think "path b" is already some sort of copy of "path a".But there were few changes in "path a".But do you want to replace the files that are exactly the same? or only just the changed ones you want to replace.


--------------------
Hemant Kumar
user posted image
hemant@linuxhelp.net
Go to the top of the page
 
+Quote Post
end-user
post Dec 11 2004, 11:06 PM
Post #3


Whats this Lie-nix Thing?
*

Group: Members
Posts: 7
Joined: 8-November 04
Member No.: 4,132



'a' is a live directory with changing content. 'b' is a backup. I want to mirror changes in 'a' to 'b'. If file haven't changed, it'd be a waste of resources to overwrite them. The trickiest thing seems to be if a file is removed from 'a' to also remove it from 'b'. New and modified files should be copied (overwrite) normally.
Go to the top of the page
 
+Quote Post
end-user
post Dec 16 2004, 04:34 PM
Post #4


Whats this Lie-nix Thing?
*

Group: Members
Posts: 7
Joined: 8-November 04
Member No.: 4,132



Anyone have any suggestions?
Go to the top of the page
 
+Quote Post
Termina
post Dec 17 2004, 12:52 AM
Post #5


RMS is my Hero
******

Group: Support Specialist
Posts: 862
Joined: 18-February 04
From: Wisconsin
Member No.: 2,404



I belive what you want is:

QUOTE
cp -r /patha /pathb


While you said you don't want to overwrite backed-up files that havn't changed... well that's a bit over my head, sorry. smile.gif While I'm positive you could do that fairly easily with a bash script... well, I havn't gotten into programming. =P

Seems to me that unless you're copying over gigs and gigs of stuff more often than every hour or so, it won't be a real waste of resouces.


--------------------
*Points finger at the author above him* They're a witch! Burn them!
---
Vist my website!
Join me in IRC! Server: st0rage.org Channel: #UnhandledExceptions
Go to the top of the page
 
+Quote Post
end-user
post Dec 17 2004, 10:37 PM
Post #6


Whats this Lie-nix Thing?
*

Group: Members
Posts: 7
Joined: 8-November 04
Member No.: 4,132



Actually, I am copying 9+ GB every day, between several different machines. Also, I need a solution that will 'copy' deletions. I was looking at diff, but when I compare directories, I get extra text, not just the file name.
Go to the top of the page
 
+Quote Post
Hemant
post Dec 18 2004, 06:08 AM
Post #7


RMS is my Hero
******

Group: Support Specialist
Posts: 782
Joined: 6-October 02
From: Trichy,INDIA
Member No.: 29



This is really a bit tricky...
but something like this can be done
CODE
#!/bin/bash
APREFIX="/usr/src/"
BPREFIX="/usr/backup"
SIZE="du" #the command to check the size
#here the variables are declared in way,assuming initial path is different after that i think
#pathA and pathB will be the same,something like A=/usr/src/liveA,B=/usr/backup/BackB
#so here ultimately liveA and BackB are folders on which any operation will be done.
cd APREFIX/liveA
for x in `ls -R`
do
 sizeA = du "$x"
 sizeB = du "$BPREFIX/BackupB/$x"
 if[sizeA eq sizeB]
 do
     #do nothing
 else
     cp $x "$BPREFIX/BackupB/"
done
cd $BRREFIX/BackupB
for x in `ls -R`
do
  if[$APREFIX/liveA/"$x"] #here also just check if the file exists in pathA.You can do that easliy.
#i just forgot the command for checking up,if a file exists.
  do
    #do nothing
  else
      rm "$x" #remove "$x" because the file is no longer in "A"
done


The above code is given as a proof of concept.I am replying from a windows machine so i can't check the exact syntax.But as you see i have used the size of the files as the deciding factor.But that may not be foolproof so you can check the timestamp.But as i said i am replying from a windows machine.so it difficult for me to give an exact script.


--------------------
Hemant Kumar
user posted image
hemant@linuxhelp.net
Go to the top of the page
 
+Quote Post
Termina
post Dec 20 2004, 05:33 PM
Post #8


RMS is my Hero
******

Group: Support Specialist
Posts: 862
Joined: 18-February 04
From: Wisconsin
Member No.: 2,404



Sorry for the late reply!

I cleaned it up a bit, and got it to work. (And learned some BASH scripting while I was at it, yay!)

Thanks for the great script, Hemant! *steals it*

One little thing I did to change it was to show what file(s) it's backing up. Not neccissary, and you'll no doubt want to remove that after testing it, but it's nice to know the first time you run it that it hasn't frozen. Also, I *think* you have to place this in APREFIX. Not sure why.

Also used du -b instead of just du (du -b = bytes, just du doesn't seem very reliable to see if the file has been changed, especially for multiple small files)

Removed the directories put after APREFIX/BPREFIX, since they didn't seem to be needed and got in the way.



CODE
#!/bin/bash
#Made by Hemant
#Stolen by Termina (Ha, ha!)
APREFIX="/home/andrew"
BPREFIX="/usr/backup"
SIZE="du -b" #the command to check the size
cd $APREFIX
for x in `ls -R`
  do
  sizeA = du -b  "$x"
  sizeB = du -b "$BPREFIX/$x"
     if [ "sizeA" = "sizeB" ]
        then
           echo "File sizes the same"
        else
           cp -r $x $BPREFIX
           echo $x
     fi
cd $BRREFIX
for x in `ls -R`
  do
     if [ "$APREFIX"/"$x" ]
        then
           echo $x
           #do nothing
     else
        rm "$x" "$x" because the file is no longer in "A"
     fi
  done
done


--------------------
*Points finger at the author above him* They're a witch! Burn them!
---
Vist my website!
Join me in IRC! Server: st0rage.org Channel: #UnhandledExceptions
Go to the top of the page
 
+Quote Post
Hemant
post Dec 21 2004, 03:50 PM
Post #9


RMS is my Hero
******

Group: Support Specialist
Posts: 782
Joined: 6-October 02
From: Trichy,INDIA
Member No.: 29



Thanks termina for the exact code!!!(that is an excellent example of code reusability)

But i guess we missed the END-USER!!! biggrin.gif


--------------------
Hemant Kumar
user posted image
hemant@linuxhelp.net
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 17th October 2017 - 12:08 PM