неделя, януари 20, 2013

WinSCP ver.2

Update на стар пост: Ta... mantis backup
Като цяло задачата е от Windows-ки хост да се синкват/ъплоадват файлове към Linux ски такъв през SSH (и без това за management си го има SSH service... та да не се инсталират допълнителни)
Иначе обмислях и други варианти като WebDav, curlfs, sshfs, Samba, NFS ама всичките си искат допълните софтуери.
Та варианта който се ползва е на базата на SCP.
В моят случай най-голeмият минус е това, че SSH_User и SSH_User_Password са в clear text.
1. pscp.exe от пакета PuTTY
E:\_Backups\pscp.exe -scp -batch -l SSH_User -pw SSH_User_Password  File_To_Upload.txt example.com:/home/data/

2. WinSCP.exe от пакета WinSCP (single command line)
E:\_Backups\winscp.exe /console /command "option batch continue" "option confirm off" "open SSH_User:SSH_User_Password@example.com" "lcd E:\_Backups\tmp\" "synchronize remote -criteria=time" "exit"
Същественият плюс тук е възможността да се синкват файлове по критерий time

3. WinSCP.exe от пакета WinSCP (via script)
Същественият плюс тука е наличието на подробен лог-файл за извършваните действия (за debug/audit е супер)

bat-file : winscp.bat

E:\_Backups\tmp\winscp.exe /console /hostkey /script=E:\_Backups\tmp\1synchronize.txt /log=E:\_Backups\LOGs\"%date%"session.txt
/hostkey - да се съгласява с какъвто и fingerprint да му се представи сървъра отсреща

файла с командите които да се изпълнят:1synchronize.txt 

# Automatically answer all prompts negatively not to stall
# the script on errors
echo on

# on|off|abort|continue
# Toggles batch mode (all prompts are automatically replied negatively). 
# When on, it is recommended to set confirm to off to allow overwrites. 
# With abort script is aborted when any error occurs. 
# With continue all errors are ignored. 
 option batch continue

# Disable overwrite confirmations that conflict with the previous
#option confirm off
option confirm on

# Connect using a password
# open user:password@example.com
# Connect
open SSH_User:SSH_User_Password@example.com -hostkey="ssh-rsa 2048 e0:e5:aa:f8:35:f3:c4:00:16:57:a2:ac:04:66:0f:fc"

# Change remote directory
cd /home/data/

# Change local directory
lcd E:\_Backups\tmp\files

# Force binary mode transfer
option transfer binary

### When the first parameter is local, changes from remote directory are applied to local directory. 
### When the first parameter is remote, changes from the local directory are applied to the remote directory. 
### When the first parameter is both, both local and remote directories can be modified.
### http://winscp.net/eng/docs/scriptcommand_synchronize

# Synch local directory with remote one 
 synchronize remote -criteria=time

# Disconnect
close
# Exit WinSCP
exit


ToDo: passwordless (key-files) SSH authentication and authorization