WINSCP synchronizing server data to a PC disk on a command-line basis

Source: Internet
Author: User
Tags ssh port

Backup files are generated daily on the server and need to be synced to the local PC hard drive using the WINSCP tool. Usually is a graphical interface with the mouse click to synchronize, inefficient, so wrote WinSCP automatic synchronization script, and added to the scheduled task automatically run.

1. Create a backup private account on the Linux server:

chattr -i/etc/{passwd, Shadow,group,gshadow}useradd bak_userecho' 123456789 ' passwd --stdin bak_userchattr +i/etc/{passwd, Shadow,group,gshadow}  su - bak_userexit

2. Create the WINSCP synchronization script C:\SERV_BAK.txt, which synchronizes the data to the Local:

OptionEcho offoption Batch Continueoption confirmoff#no need to confirm direct Operation option Transfer binary
Option Synchdelete on#server If the file is not available, remove the local file from the open sftp:Bak_user:[email protected] Server ip:33302 #fill in the server account, password, IP, ssh port, respectivelyCD/Backup/bitmore.com #in the directory that you want to synchronize, all subdirectories and files in that directory are synchronized with the LCD C:\bitmore.com #Enter the local destination directory, the directory must be established beforehand, otherwise the file will be uploaded to the WINSCP program directory. Synchronize local#equivalent to Rsync, which synchronizes the data from the server side to local. Local: Sync locally. Remote: Sync to peer closeExit

3. Execute in Windows side CMD window:

CD Files (x86) \winscpwinscp. Exe/console/script=c:\serv_bak. txt If you have multiple servers to synchronize, it is best to write a WINSCP script separately for each server. And then combine them into *. bat file Batch execution: Start cmd /C "D:\Program Files (x86) \winscp\winscp.exe"/console/script=c:\serv_bak.txt
Start cmd /C "D:\Program Files (x86) \winscp\winscp.exe"/console/script=c:\serv_bak02.txt
Start/min cmd/c "D:\Program Files (x86) \winscp\winscp.exe"/console/script=c:\serv_bak03.txt

The above command will open 3 cmd windows at the same time to execute. Start: Opens a new window,/min: Minimized run main window,/C: Original window closed

4. Add the Windows scheduled task to automatically complete the synchronization operation at the scheduled time:
Run--"taskschd.msc

Get. The PC keeps booting after work. The hands were freed from this.

Enter Help:
Winscp> Help
Call executes any remote shell command
CD changes Remote working directory
chmod changing remote file permissions
Close closing Sessions
Exit close all sessions and end the program
Get download files from a remote directory to a local directory
Help Display assistance
Keepuptodate in a remote directory continuously reflects changes in the local directory
LCD changes local working directory
LLS listing the contents of a local directory
ln New remote Symbolic link
LPWD Show Local working directory
LS lists the contents of the remote directory
mkdir New Remote Directory
MV Move or rename remote files
Open Connect to Server
option to set or display the value of a script option
Put upload files from a local directory to a remote directory
PWD Displays remote working directory
RM Delete remote Files
RmDir Deleting a remote directory
Session lists connected sessions or selects active sessions
Synchronize synchronizing a remote directory with a local directory

WINSCP synchronizing server data to a PC disk on a command-line basis

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.