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 ...
- 05-10-2010 #1Just Joined!
- Join Date
- May 2010
- Posts
- 3
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:
- Create a .TAR of the folder to be backed up
- Upload the folder to the FTP server
- Delete the previous night's backup
I am new to Linux scripting and would appreciate any help. Thanks in advance.
- 05-11-2010 #2Just Joined!
- Join Date
- Apr 2010
- Location
- India
- Posts
- 3
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
- 05-12-2010 #3Just 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
- 05-12-2010 #4Just Joined!
- Join Date
- Apr 2010
- Location
- India
- Posts
- 3
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
- 06-07-2010 #5Just 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
- 07-09-2010 #6Just 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).


Reply With Quote
