關於 PHP, Linux, Open Source 及個人生活記載的網誌。
RSS icon
  • Redhat 自動 FTP 傳送備份

    Posted on December 13th, 2007 Sam Tang No comments

    如果在 crontab 備份檔案後,想將檔案透過 FTP 傳送到其他伺服器,可以用以下方法編寫 shell script:

    #!/bin/sh
    FTPHOST="ftp.server.address"
    USERNAME="ftp-username"
    PASSWORD="ftp-password"
     
    # 本機儲存 .tar.gz 備份檔的目錄
    FILE="/backup/dir"

    # FTP Server 備份目錄
    BACKUPDIR="/ftpserver/backup"

    # 登入 FTP Server 並傳送檔案
    ftp -n FTPHOST < user $USERNAME $PASSWORD
    cd $BACKUPDIR
    mput $FILE/*.tar.gz
    quit
    EOF

     
    shell script 儲存後,需要執行 "chmod +x filename.sh" 給予執行權限,然後放到 crontab 裡面便完成了。


    Leave a reply

    *
    To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
    Click to hear an audio file of the anti-spam word