Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Basic BASH FTP script

  1. #1
    Join Date
    Jun 2008
    Location
    Omaha, NE
    Posts
    526

    Default Basic BASH FTP script

    You'll have to forgive me, but I know basically nothing about bash scripting.

    I'm setting up a PC for my mother, and I need to automate a basic backup system for her since she isn't going to back up her files herself.

    Can someone help me with a basic script to backup her:

    /home/cheri/Desktop/
    /home/cheri/Pictures/
    /home/cheri/Documents/

    folders? I have bzip2, gzip and p7zip installed. I assume p7zip is going to give the best compression.

    If I can compress these folders, and then ftp them that would be great. I'm about to change webhosts because my current one is getting unbearably slow, but if you can help with the script and just put foo in various places, I can fill in the details for the ftp server, login, password, etc.

    Thanks!

  2. #2
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,683
    Blog Entries
    4

    Default Re: Basic BASH FTP script

    First of all, don't use ftp, unless it's just within a LAN, use scp.

    And anyway if you use scp, you can specify the login, etc on the command line. You can even use key authentication and avoid sending passwords.

  3. #3
    Join Date
    Jun 2008
    Location
    Omaha, NE
    Posts
    526

    Default Re: Basic BASH FTP script

    I'm not familiar with scp but if I can use it to get the files off her box, that would be great. My main concern is that she isn't willing to backup to DVD or anything, yet somehow it is my issue when her HDD dies. Her files aren't necessary anything I'm overtly worried about security with. I assume the password would have to be in the script to be fully automated via cron. An encrypted password file is fine, but again I'm not overtly paranoid here. The script would reside on her PC and just transfer files to an FTP server.

  4. #4
    houghi NNTP User

    Default Re: Basic BASH FTP script

    enderandrew wrote:
    > I'm setting up a PC for my mother, and I need to automate a basic
    > backup system for her since she isn't going to back up her files
    > herself.


    Backup should always be somewhat automatic.

    > Can someone help me with a basic script to backup her:
    >
    > /home/cheri/Desktop/
    > /home/cheri/Pictures/
    > /home/cheri/Documents/
    >
    > folders? I have bzip2, gzip and p7zip installed. I assume p7zip is
    > going to give the best compression.


    Why not do a backup of /home? Also backup is the second most importand
    part. The most importand part is restoring.

    > If I can compress these folders, and then ftp them that would be great.
    > I'm about to change webhosts because my current one is getting
    > unbearably slow, but if you can help with the script and just put foo
    > in various places, I can fill in the details for the ftp server, login,
    > password, etc.


    I use http://en.opensuse.org/StoreBackup
    Advantage is the restoring stuff is as easy as copying a file. Another
    advantage is incremential backups.

    Another advantage, I find, with using an already existing script is that
    you won't forget anything.

    Otherwise the program easiest to use for ftp in a script would be
    ncftp.

    houghi
    --
    This was written under the influence of the following:
    | Artist : Anouk
    | Song : Help
    | Album : Hotel New York

  5. #5
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,683
    Blog Entries
    4

    Default Re: Basic BASH FTP script

    Another program that does pretty much all you want is curl. You can store the passwords in a .netrc file, just like ncftp.

  6. #6
    indian99 NNTP User

    Lightbulb Re: Basic BASH FTP script

    here you have a little simple script you need
    install ncftp and change the values for ftp server
    Code:
    #!/bin/bash
    
    # change the username, password, ftp host and remote direcotry
    ftp="/usr/bin/ncftpput -u username -p password ftp.host.com /pub/backups/"
    
    # here you can wirte the list of directories you want to backup
    DIRS="/home/cheri/Desktop /home/cheri/Pictures /home/cheri/Documents"
    
    DATE=$(/bin/date +%Y%m%d)
    /bin/tar czf backup.$DATE.tgz $DIRS 2> /dev/null
    /usr/bin/md5sum backup.$DATE.tgz > backup.$DATE.MD5SUM
    $ftp backup.$DATE.tgz backup.$DATE.MD5SUM
    exit 0

  7. #7
    Join Date
    Jun 2008
    Location
    Atlanta, Georgia, USA
    Posts
    2,429

    Default Re: Basic BASH FTP script

    So many possibilities . . .

    I'm not entirely clear on where you want to script to run, the client or the server? Assuming the former, it is an upload; can you configure the server as needed? (If the latter, it is trivial to set up vsftp in YaST on the client.)

    If you do have control of the server, rsync is a very good alternative. It will only transfer new or changed files, whereas ftp or a copy method will re-write all the data every time. And rsync is faster, too. So the backup time will be considerably less. Rsync can write to the ftp server directory so that the files can be later accessed that way, if desired. (There is also an rsync derivative which enables incremental backups, but it appears that you only want a single snapshot of the files.) Rsync can run from either client or server, logging on to the other machine. But it's preferred that the receiving machine have the rsync daemon running; that gives you better control and is more secure.

    If interested in this approach, reply back and we can provide some pointers.

  8. #8
    Join Date
    Jun 2008
    Location
    Omaha, NE
    Posts
    526

    Default Re: Basic BASH FTP script

    I don't run my own server. I pay for a webhost, which in turn gives me a FTP server, or I'd totally go with something like rsync.

    Thanks everyone!

  9. #9

    Default Re: Basic BASH FTP script

    lftp may be what you're after.

    From man

    lftp has builtin mirror which can download or update a whole directory tree. There is also reverse mirror (mirror -R) which uploads or updates a directory tree on server.

    Webpin

  10. #10
    Join Date
    Jun 2008
    Location
    Cleveland, TN USA
    Posts
    412

    Default Re: Basic BASH FTP script

    Quote Originally Posted by indian99 View Post
    here you have a little simple script you need
    install ncftp and change the values for ftp server
    Code:
    #!/bin/bash
    
    # change the username, password, ftp host and remote direcotry
    ftp="/usr/bin/ncftpput -u username -p password ftp.host.com /pub/backups/"
    
    # here you can wirte the list of directories you want to backup
    DIRS="/home/cheri/Desktop /home/cheri/Pictures /home/cheri/Documents"
    
    DATE=$(/bin/date +%Y%m%d)
    /bin/tar czf backup.$DATE.tgz $DIRS 2> /dev/null
    /usr/bin/md5sum backup.$DATE.tgz > backup.$DATE.MD5SUM
    $ftp backup.$DATE.tgz backup.$DATE.MD5SUM
    exit 0
    To create an md5sum wouldn't you need to use "create_md5sums" instead of "md5sum"?
    Last edited by vendion; 11-Jun-2008 at 19:49. Reason: Making the commands in my post stand out more
    "We must plan for freedom, and not only for security, if for no other reason than only freedom can make security more secure." Karl Popper

Page 1 of 2 12 LastLast

Posting Permissions

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