The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
creating link for a file of remote server sanjay1979 SUN Solaris 7 06-03-2009 03:32 AM
Solaris Backup Server with ZFS and rsync iBot Solaris BigAdmin RSS 0 03-25-2009 07:15 PM
Creating and using a /.rsync/exclude komputersman Shell Programming and Scripting 0 03-19-2008 06:13 PM
SFTP:error while creating folders on remote server vgs Shell Programming and Scripting 0 08-01-2007 04:01 PM
creating a file on remote directory using sftp borncrazy Shell Programming and Scripting 1 07-11-2004 03:48 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 4 Weeks Ago
nck nck is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 17
Rsync creating dirs on remote server

I am using 'rsync' to backup to a remote server as follows:

rsync user@remote.server.net:backup_dir/server_dir

Error:

rsync: mkdir "/home/usr/backup_dir/server_dir" failed: No such file or directory (2)

The remote directories, backup_dir/server_dir , do not exist.

Is it possible for 'rsync' to create the subdirs? I know it will create the single level directory.
  #2 (permalink)  
Old 3 Weeks Ago
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2005
Location: Switzerland - GE
Posts: 1,569
Have you tried with the -p option of mkdir?
  #3 (permalink)  
Old 2 Weeks Ago
Skaperen Skaperen is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 3
Rsync will create ONE directory level when it is the last component in the target path. Any other directory levels must already exist. If you need to have more than that number of levels created, AND if the directory levels to be created all exist in the source tree, you can get rsync to do this. The method involves using the --include and --exclude options to select the specific directory to be copied, and specify the source and target at a higher level (so that the the parent of the target exists). Unfortunately, it is complicated, and gets more complicated with more levels. But basically, you shorten the source and target paths equally, and fill in the paths through the --include options. You also use the --exclude options to block copying of other directory levels.

Here is a command example:

Code:
rsync -av --include projects --include projects/newprogram --include 'projects/newprogram/**' --exclude 'projects/**' --exclude '**' /home/skaperen/programs/. skaperen@backupserver:/home/skaperen/programs

This copies "/home/skaperen/programs/projects/newprogram" and all its subdirectories.

The order of the --include and --exclude options is important to rsync. It checks each file to be considered against these options in order and applies the first match. This will create "/home/skaperen/programs" in the target if it does not exist. Ending the source path with "/." ensures that if the target directory already exists, another directory called "programs" will not be created in it (which would end up with "/home/skaperen/programs/programs" with a duplicate of everything). The subdirectories "projects" and "projects/newprogram" will be created as recursive subdirectories.

So, for your situation, find the directory level where you can be sure the parent directory really does exist (perhaps the home directory as in my example). Then express every level you want to copy as discrete --include options. Use the "**" (a double asterisk matches multiple directory levels while a single asterisk matches exactly one directory level). Then add --exclude options to exclude everything else at each level. Be sure to do an --exclude for "**" as the final one.

Don't forget to append "/." on the source path to avoid placing the source directory inside the target directory (or leave it off if that is your intention). You can append "/." on the target path if you want to prevent it from creating it when it does not exist. You need to put the options with * or ** in quotes to prevent your shell from expanding it from existing files.

I hope that helps. If you need to change a directory name so the target is different than the source, you need to do that as the target and source arguments (not in --include). That means the parent directory of a name-changed target must exist. If the above cannot be achieved because of the renaming needs, then you will have to resort to using ssh into the target to run "mkdir -p" with the target path to get the needed directories to exist.
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0