?
Solved

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

Posted on 2007-11-30
3
Medium Priority
?
792 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 2000 total points
ID: 20387088
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
ID: 20398695
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
ID: 20410770
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Here in this article, you will get a step by step guidance on how to restore an Exchange database to a recovery database. Get a brief on Recovery Database and how it can be used to restore Exchange database in this section!
Steps to fix error: “Couldn’t mount the database that you specified. Specified database: HU-DB; Error code: An Active Manager operation fail”
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

862 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