ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm trying to write a shell script that performs regular backups of a directory to a FTP server. I googled around a bit, and I found the following script in a howto:
#!/bin/sh
HOST='ftp server address'
USER='ftp username'
PASSWD='ftp password'
FILE='filename'
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put $FILE
quit
END_SCRIPT
exit 0
Now, this is a good start, but I need this script to upload an entire directory, not just one file. So, my questions are:
-Using the basic ftp program for linux, is it possible to tell the ftp program to simply upload a directory? If so, is it possible for the script to go through the local directory and only upload those files that are newer than those on the server, or completely new?
-If it isn't, how do you script a shell script that recurses through a directory and just uploads every file it comes across via ftp, while mirroring the local file structure on the ftp?
Also, if anyone has a simpler method of doing this than with a shell script and ftp, that would be awesome too.
Is there any reason you have to use a basic ftp program? Life will be much easier if you can install ncftpput (part of the ncftp suite). Uploading a directory is pretty simply - I do my backups that way as well. The meat of the upload bit looks something like this:
upload all of $BACKUP_DIR (because of the -r) to a directory on $BACKUP_HOST called "backups"
delete local files when done uploading (because of the -DD - you probably won't want this)
no output because we're running in a script (from -V)
don't overwrite destination files until the upload is done (from -S .tmp)
make the directory "backups" on $BACKUP_HOST if it doesn't already exist (from -m)
there's a lot of other useful ftp programs -
list the contents of an ftp dir and echo to stdout
get single file or directory (good for scripts as well)
and a nice interactive ftp client.
Distribution: Anything NOT SystemD (ie. M$) related.
Posts: 918
Rep:
i forgot, since you are looking for 'regular' backups, sbackup has plenty of configurations for time/day, regular intervals, etc.
it even has ssh.. and the most important part is, IT WORKS!
i tried it.
it's origins are interesting as well.. it was developed last summer as some sort of google competition.. and it was so impresive that it made it's way right into the debian repositorys
Excellent! ncftpput seems to be exactly what I was looking for- my requirement of the normal ftp program was due to my ignorance of the existence of better things. sbackup would be good if the computer that is going to be running it had a gui, but alas, it's a console-only headless server- ncftpput seems like the better choice for that. That being said, I may very well get sbackup on my personal machine, as it seems like an excellent program.
Thanks for the help, BrianK and halvy- this time last night, I was thinking I would have to write some sort of nightmare recursive shell script- this is definitely much easier!
Distribution: Anything NOT SystemD (ie. M$) related.
Posts: 918
Rep:
coool, backups are another thing lin needs to bone up on. i'v tried alota different backup progs and was awefully glad to stumble upon simpe-backup. i tried to setup bacula a coupla times, and i think they need to change the name to bitchula
hopefully you will be able to tear ncftpput and/or sbackup apart and see how it ticks so you can advance your scripting knowledge.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.