Linux/unix system inter-backup script

Source: Internet
Author: User

This is a shell script I wrote earlier, used to Linux/unix automatic file backups between systems.


The main features of the script are:

    1. Synchronization or copying of files for the day between different servers; requires expect command support, Rhel and AIX testing is normal and requires expect command Support (Unix systems need to modify the first line of the script to #!/bin/bash the system shell);

Usage Requirements:

The system expect command is available; the destination (remote) device folder exists and can have appropriate permissions.
Where applicable (The following scenario tests are normal):
A device the same folder copies files to one or more remote devices in the same or different folder
One device different folder copy files to one or more remote devices in the same or different folder
Non-real-time synchronization of files between AIX systems
Non-real-time synchronization of files between Aix and Rhel systems
Non-real-time synchronization of files between Rhel systems

Please test before use.

The aix_trans.sh script code is as follows:

#!/bin/bash#author:zj#qq:1037509307#datetime: 2016-07-09 01:41:14#description: #用于不同服务器间当天的文件的同步或拷贝 ; requires expect command support, Rhel and AIX testing is normal and requires expect command support. #aix系统需要修改头文件; #使用要求: The system expect command is available; the destination (remote) device folder exists and is accessible. #适用情况: #一台设备同一文件夹向一台或多台远程设备相同或不同文件夹拷贝文件 # A different folder for a device copy files to one or more remote devices in the same or different folder #version: v1.3##################### ################## #源设备信息 ########################################## #源设备文件路径1   (end of Path without slash/) source_path_1=/ usr/appsoft/easycfg/system_check/warnlog# source Device file Compression package name 1file_name_1=file1.zip# If you need to synchronize other folders of the device, continue adding the variable in the format above, example # Source Device file path 2#source_path_2=xxxx# source device file Compression package name 2#file_name_2=file2.zip################################## #第一台目标设备信息 ##### ################################## #目标设备IP地址Target_IP_A =192.168.101.206# target device password [email protected]# Target device file storage path (make sure that the folder exists and is accessible) target_path_a1=/usr/appsoft/jieya# if you need to sync files to a different folder on the device, continue adding file-store paths to variables, example #target_ path_a2=/usr/appsoft/jieya1#target_path_a3=/usr/appsoft/jieya2# If you need to add additional target devices, please follow "first target device Information" to add, example: ############# ##################### #第二台目标设备信息 ####################################### #目标设备IP地址 #target_ip_b=192.168.101.206# target device password #[email protected]# Target device file storage path (make sure that the folder exists and is accessible) #Target_Path_B1 =/usr/appsoft/jieya################################################## ######################################### #Get_Syslog () {lang=enmonth= ' date +%b ' day= ' date +%e ' Ip=$ 1passwd=$2source_path=$3target_path=$4file_name=$5cd  "${source_path}" ls -l | egrep  "$ {Month} [[: Space:]]+${day} '  | awk  ' {print $9} '  | xargs zip -r ${file_name }expect -c  "Set timeout -1spawn scp -r -p ${source_path}/${file_name}  [email protected]${ip}:${target_path}expect {\ "*yes/no") \ " {send \" yes\r\ "; exp_ Continue}\ "*password:\"  {send \ "${passwd}\r\"; exp_continue}\ "*unreachable\"  {exit 1}\ "* Permission denied*\ " {exit 2}\" *no route to host*\ " {exit 3}\" *failure *\ " {exit 4}\" *no suCh file or directory*\ " {exit 5}\" *no match*\ " {exit 6}\" *failed*\ "  {exit 7}expect eof}spawn ssh [email protected]${Ip} cd  $Target _path  && unzip -o  $File _name -d  $Target _PATH && RM -RF   $Target _path/$File _nameexpect {\ "*yes/no) \"  {send \ "Yes\r\" exp_continue}\ "*password:\"  {send \ "${passwd}\r\"; exp_continue}\ "*unreachable\"  {exit 1}\ "*Permission denied*\"  {exit 2}\ "*no route to host*\"  {exit 3}\ "*failure*\"  {exit 4}\ "* No such file or directory*\ " {exit 5}\" *no match*\ " {exit 6}\" * Failed*\ " {exit 7}expect eof}"}  #Get_Syslog右括号 #tips: #Get_Syslog   target host IP   destination host password   Source Host file path   destination host file path   Compress package name #如果需要传送多个文件夹的文件, add get_syslog  "${target_ip_a}" in the following command format   "${TARGET_PASSWD_A} " " ${source_path_1} " " ${TARGET_PATH_A1} " " ${file_name_1} "#示例 #get_syslog " $Target _ip_a "   "$Target _passwd_a"   "$WEB _path_from_2"   "$Target _path_a1"   "$File _name_2"

This article is from the "Future People" blog, please be sure to keep this source http://zaa47.blog.51cto.com/6181689/1927498

Linux/unix system inter-backup script

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.