Find the answer to your Linux question:
Results 1 to 6 of 6
I need to write a Bash script that will automatically backup a folder of files each night to an FTP server. Ideally the script would do the following: Create a ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2010
    Posts
    3

    Exclamation Bash Script for FTP Backup


    I need to write a Bash script that will automatically backup a folder of files each night to an FTP server. Ideally the script would do the following:

    1. Create a .TAR of the folder to be backed up
    2. Upload the folder to the FTP server
    3. Delete the previous night's backup


    I am new to Linux scripting and would appreciate any help. Thanks in advance.

  2. #2
    Just Joined!
    Join Date
    Apr 2010
    Location
    India
    Posts
    3

    Thumbs up

    Quote Originally Posted by fdavino90 View Post
    I need to write a Bash script that will automatically backup a folder of files each night to an FTP server. Ideally the script would do the following:

    1. Create a .TAR of the folder to be backed up
    2. Upload the folder to the FTP server
    3. Delete the previous night's backup


    I am new to Linux scripting and would appreciate any help. Thanks in advance.

    Hello,
    A simple script can be use to transfer the files to FTP server automatically..
    ======================================
    HOST=X.X.X.X
    USERNAME=XXXX
    PASS=XXXX
    tar -czf FOLDER_TO_BE_BACKEDUP.tar.gz FOLDER_TO_BE_BACKEDUP/*
    ftp -n -i $HOST <<-EOF
    user $USERNAME $PASS
    pwd
    delete FOLDER_TO_BE_BACKEDUP.tar.gz
    mput FOLDER_TO_BE_BACKEDUP.tar.gz
    bye
    ======================================
    NOTE : X.X.X.X represents destination IP Address

    Place above code in a file say "ftp_data_transfer"
    chmod 755 ftp_data_transfer
    You need to set the crontab to run this script daily in the midnight or at any time you want.

    Regards
    Marsh
    Linux Technical Support Executive
    eukhost.com

  3. #3
    Just Joined!
    Join Date
    May 2010
    Posts
    3
    Thanks vmandale,

    That seems logical, but it doesn't seem to be working. I filled in all of the blanks in the script, and everything runs fine up to the "ftp -n -i HOST$" Once it opens the ftp session, the script just hangs there and waits for my input. I can complete the process by entering each of the lines manually in terminal. Do you have any idea why this would happen?

    Thanks Again,
    Frank

  4. #4
    Just Joined!
    Join Date
    Apr 2010
    Location
    India
    Posts
    3

    Thumbs up

    Quote Originally Posted by fdavino90 View Post
    Thanks vmandale,

    That seems logical, but it doesn't seem to be working. I filled in all of the blanks in the script, and everything runs fine up to the "ftp -n -i HOST$" Once it opens the ftp session, the script just hangs there and waits for my input. I can complete the process by entering each of the lines manually in terminal. Do you have any idea why this would happen?

    Thanks Again,
    Frank
    Hello Frank,
    I guess I forgot to write EOF at the end of script. The script should be :
    ======================================
    HOST=X.X.X.X
    USERNAME=XXXX
    PASS=XXXX
    tar -czf FOLDER_TO_BE_BACKEDUP.tar.gz FOLDER_TO_BE_BACKEDUP/*
    ftp -n -i $HOST <<-EOF
    user $USERNAME $PASS
    pwd
    delete FOLDER_TO_BE_BACKEDUP.tar.gz
    mput FOLDER_TO_BE_BACKEDUP.tar.gz
    bye
    EOF
    ======================================

    Also please paste the script you are using and let me know the exact output you are getting after running the script.

    Regards
    Marsh
    Linux Technical Support Executive
    eukhost.com

  5. #5
    Just Joined!
    Join Date
    May 2010
    Posts
    3

    This is my Script

    HOST=192.168.1.101
    USERNAME=admin
    PASS=password
    tar -czf /home/Frank/script.tar.gz /home/Frank/script/*
    ftp -n -i $HOST <<-EOF
    user $USERNAME
    pwd $PASS
    delete script.tar.gz
    mput script.tar.gz
    bye
    EOF

    What is the purpose of the <<-EOF on the line that starts with ftp?
    So far I haven't gotten it to work.

    Thanks in advance,
    Frank

  6. #6
    Just Joined!
    Join Date
    May 2010
    Posts
    5
    You can find an interesting backup script that uses SSH and never stores the backup on the sending machine's disks so it enables you to do backup even on nearly full machines. Google: 'Backing up Linux web server live via SSH' (I can't post links yet).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •