2013年7月11日 星期四

linux rsync linux-rsync

rsync -av --iconv=utf-8,big5 root@1.2.3.4:/Source/Folder/ /TargetFolder/SubFolder/

rsync -av /Folderl/ /backup2/backup/Folder
nice -n 10 /usr/bin/rsync

rsync 是個很有用的工具,可以拿來同步兩台電腦間的資料。不過 rsync 有一個大問題就是:如果兩台電腦的語系不同的話,那就會造成困擾。像是 Mac OS X 都是用 UTF-8,而 FreeBSD 的 Server  上用 big5 已經用很久了也不太方便換,如果直接 rsync 那就一定有一邊看到亂碼。真的要用的話那就只能繞路了。之前處理的方式是用 samba 轉一層 mount 之後再做 rsync,利用 samba 來轉換,可以正常運作,不過花了很大的力氣。




Methodrsync,2,3,
sing machine
local file to local file
rsync [option]... source [source]...Dest
rsync --delete -av /sourceDirectory/subDirectory /targetDirectory
Local to Remote
rsync [option]... Source [Source]... [user@]host:Dest
rsync [option]... Source [Source]... [user@]host::Dest
Remote to Local
rsync [option]... [user@]host::Source [Dest]           
rsync [option]... [user@]host:SourceDest           
rsync [option]... rsync://[user@]host[:PORT]/Source [Dest]
sshrsync -av -e ssh user@rsh.server:/sourceDirectory /targetDirectory

ssh-keygen -t rsa  
# hit return three times 
   
ssh-copy-id -i ~/.ssh/id_rsa.pub username@remote_host  
# enter your password for username on remote_host
    
cat > /etc/cron.daily/remote_backup  
#!/bin/sh  
rsync -e 'ssh -p 22' -avzp /some/dir remote_host:/var/backups/some_host  
^D    

chmod +x /etc/cron.daily/remote_backup    
ssh username@remote_host mkdir /var/backups/some_host
daemon
Step
1service rsync restart && 看 /etc/xinetd.d/rsync 即可
2vi /etc/rsyncd.conf
motd file = /etc/rsyncd.motd  
log file = /var/log/rsyncd.log  
pid file = /var/run/rsyncd.pid  
lock file = /var/run/rsync.lock    



[simple_path_name]     
path = /rsync_files_here && path - this is the 
actual filesystem path to where the files are rsync'ed from and/or to.
comment = My Very Own Rsync Server     
uid = nobody     
gid = nobody     
read only = no     
list = yes     
auth users = username     
secrets file = /etc/rsyncd.scrt


nano /etc/rsyncd.scrt
window2000:window2000sPassword
hongkong2000:hongkong2000sPassword

              
3client password

#setenv RSYNC_PASSWORD plaintpassword
vi PasswordFILE
chmod 640 PasswordFILE
4在 client 端可以利用:rsync --delete --password_file=PasswordFILE -av user@hostname::/dir/path /local/path

[root@linux etc]# cat /var/spool/cron/root
#05 17 * * * poweroff
01 * * * * /etc/singtime
#43 0 1 * * /etc/backup
1 1 1 * * /etc/mthBackup
59 01 * * * rsync -av --delete --exclude "*.exe" --exclude "*.EXE" /ssole/folder/ /current/sole/folder/
#59 03 * * * rsync -av --delete --exclude "*.EXE" --exclude "*.exe" /folder/subFolder/ /current/folder/subFolder/
59 22 * * * rsync -av --delete /sFolder/subFolder/ /current/folder/subFolder/

10 1 * * *  rsync -av --delete /boot/ /243d/sa/it/linux/2/boot
20 1 * * *  rsync -av --delete /root/ /243d/sa/it/linux/2/root
30 1 * * *  rsync -av --delete /etc/ /243d/sa/it/linux/2/etc
40 1 * * *  rsync -av --delete /var/spool/cron/ /243d/sa/it/linux/2/var/spool/cron

沒有留言:

張貼留言