How to automatically create a directory when Rsync backup _ server Other

Source: Internet
Author: User
Tags mkdir parent directory ssh rsync ssh server

have been accustomed to using rsync + SSH server file synchronization, but before the command parameters to find similar mkdir-p function, you can synchronize a specified file automatically on the target server to create a complete parent directory on demand. For example, some of the automatically generated directory files by month and year need to be synchronized when the file is generated:

Copy Code code as follows:

RSYNC-LPRZTW--rsh= "/usr/bin/ssh-l rsyncuser"/var/2007/12/13/1001.gif 10.0.0.1:/var/2007/12/13/1001.gif

If the/VAR/2007/12/13 directory is not previously created on the target server, the synchronization will error: Rsync:push_dir#3 "/VAR/2007/12/13" Failed:no such file or directory (2)

The previous solution was to create all the new directory structures that might be created in advance on the target server, or to immediately rsync the directory to the target server when creating a new directory on the source server.

By accident, Rsync has a-r parameter (-r,--relative use relative path names) to synchronize the entire directory structure under the relative directory to the target server specified directory. Using this parameter can automatically achieve the effect of mkdir-p, only need to change the synchronization command:

Copy Code code as follows:

Cd/var
RSYNC-LPRRZTW--rsh= "/usr/bin/ssh-l rsyncuser" 2007/12/13/1001.gif 10.0.0.1:/var/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.