Solved

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

Posted on 2007-11-30
3
784 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 500 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
API v SOA 8 63
UM7 Stop Sending packets with GPS Sensor 1 44
Migrate Thunderbird to Outlook 6 91
Best way to encrypt a xls file 8 62
The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
When it comes to security, there are always trade-offs between security and convenience/ease of administration. This article examines some of the main pros and cons of using key authentication vs password authentication for hosting an SFTP server.
This video demonstrates how to use each tool, their shortcuts, where and when to use them, and how to use the keyboard to improve workflow.
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.

734 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