Solved

Moving multiple directories on remote ssh connection, sometimes moves directories inside of each other..please help

Posted on 2007-11-30
3
779 Views
Last Modified: 2013-12-16
Hello,

I am using cygwin to create a 7 day snapshot backup of my hard drive every night.  
I basically have 7 folders, delete the oldest and move 0 to 1, 1 to 2, etc, then upload my files to 0.

I have attached the snippet.

The problem I am having is that sometimes these folders are winding up inside of each other, and then they wind up filling my hard drive up on the receiving server.

For example, folder 1 will be found inside of folder2 as you can see below when I do a ls -al *

daily.1:
total 464756
drwx------   5 user user      4096 Nov 14 16:42 .
drwx------   8 user user      4096 Nov 14 16:42 ..
drwx------   4 user user      4096 Nov 13 16:56 daily.0
drwx------  12 user user      4096 Nov 12 10:38 folder1
drwx------   5 user user      4096 Nov  1 13:40 folder2


daily.2:
total 20
drwx------   5 user user 4096 Nov 12 16:43 .
drwx------   8 user user 4096 Nov 14 16:42 ..
drwx------   4 user user 4096 Nov  8 02:46 daily.1
drwx------  12 user user 4096 Nov  8 02:46 folder1
dr-x------   5 user user 4096 Nov  1 13:40 folder2

daily.3:
total 24
drwx------  4 user user 4096 Nov  9 16:39 .
drwx------  8 user user 4096 Nov 14 16:42 ..
drwx------  3 user user 4096 Nov  7 18:39 daily.2
dr-x------  5 user user 4096 Jun 25 10:24 folder2


So my question is why are they moving inside of the folders.  I have a 3 day snapshot set up and it seems to be working perfectly.  I have checked the code to ensure it is consistent between the two.

Thanks,

Brian
@cls

@echo off
 

rem Rsync Job Control File

rem this will keep a 7 day rotating snapshot and a 3 week rotating snapshot on remote machine
 

rem This section will rotate the folders for a 7 day snapshot

c:\cygwin\bin\ssh -l USER HOST rm -Rf /home/USER/daily.7; mv /home/USER/daily.6 /home/USER/daily.7 ; mv /home/USER/daily.5 /home/USER/daily.6 ; mv /home/USER/daily.4 /home/USER/daily.5; mv /home/USER/daily.3 /home/USER/daily.4; mv /home/USER/daily.2 /home/USER/daily.3; mv /home/USER/daily.1 /home/USER/daily.2; mv /home/USER/daily.0 /home/USER/daily.1; cp -al /home/USER/daily.1 /home/USER/daily.0
 

rem this section actually transfers the files

C:\cygwin\bin\rsync -avz --delete -e c:\cygwin\bin\ssh /cygdrive/c/folder1 USER@HOST:/home/USER/daily.0/ 
 

C:\cygwin\bin\rsync -avz --delete -e c:\cygwin\bin\ssh /cygdrive/c/folder2 USER@HOST:/home/USER/daily.0/ 
 

c:\cygwin\bin\ssh -l USER HOST chmod -Rf 700 /home/USER/daily.0

Open in new window

0
Comment
Question by:puck916
3 Comments
 
LVL 40

Accepted Solution

by:
omarfarid earned 500 total points
Comment Utility
Hi,

The mv command will move one dir inside the other one if it exists.

e.g. if dir1 does not exit and I run

mv dir0 dir1

then dir0 is renamed dir1 at the same dir level
but if dir1 exists then dir0 is moved to be below dir1

You may do a check of the existance of the other dir before mv dir0 to dir1. It is also better to have all these commands in one shell script on the remote server which you call remotely.

Why do you cp -al /home/USER/daily.1 /home/USER/daily.0 ?


 
0
 
LVL 11

Expert Comment

by:jgordos
Comment Utility
you might be better served to make a tarball of the directories you want to save....

tar -cvf myArchive_<dateHere> ./dir1 ./dir2 ./dir3 <etc>

then you can compress it and move it as a unit.  

-j
0
 

Author Comment

by:puck916
Comment Utility
I do cp-al to hard link the files....although looking at the new versions of rsync (all except mac version) this is now available through an rsync argument.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Let’s list some of the technologies that enable smooth teleworking. 
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
The viewer will learn common shortcuts with easy ways to remember them. The viewer will then learn where to find all of the keyboard shortcuts, how to create/change them, and how to speed up their workflow.
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…

743 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

13 Experts available now in Live!

Get 1:1 Help Now