[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
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
?
790 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This month, Experts Exchange’s free Course of the Month is focused on CompTIA IT Fundamentals.
I originally wrote this article to compare SARDU and YUMI, but have now added Easy2Boot, since that is the one I currently use and find the easiest to create and alter.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

650 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