Find the answer to your Linux question:
Results 1 to 3 of 3
Hi. Just put in place a little script today to automatically backup my MySQL database and all of my datafiles to a FTP server as a single tarball in just ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Guru
    Join Date
    Apr 2003
    Location
    London, UK
    Posts
    3,284

    Backup to a FTP Server


    Hi.

    Just put in place a little script today to automatically backup my MySQL database and all of my datafiles to a FTP server as a single tarball in just 2 lines! Thought I would share with you guys how to do it.

    Firstly, grab yourself a copy of ftpbackup-2.1, and install it following the READ.ME file. Download from here:
    http://www2.cddc.vt.edu/linux/system...kup-2.1.tar.gz

    Then, su to root, and create a script like the following in your /root/ directory:

    Code:
    #!/bin/sh
    
    #################################################################
    # Jason's backup Script                                         #
    #                                                               #
    # Backup MySQL DB and /data/web/* to HOSTNAME        #
    #                                                               #
    #################################################################
    
    #Output mysql database to a file
    /usr/local/mysql/bin/mysqldump -u USERNAME --password=DB_PASSWORD backenddb > /data/web/phpbb_backenddb.sql
    
    #tar files and send to FTP server
    tar cvf - /data/web | ftpbackup -h HOSTNAME -u USERNAME -p PASSWORD -d public/ -b backup.tar

    So... what does this all do...

    The first part will dump a copy of a mysql database called "backenddb" to a file in /data/web/ called php_backenddb.sql. To make this work, you will need to change the USERNAME & PASSWORD and make them relevant for your database.

    The 2nd section makes a single tarball from every file, directory and subdirectory within /data/web/. It then pipes the tarball into the ftpbackup program that we downloaded and installed earlier. The FTPBackup program will now copy the tarball to the host (-h) HOSTNAME. Because it is not an anon FTP server, we need to authenticate with a username and password, this is done with the "-u USERNAME -p PASSWORD". The "-d public/" is the folder within the FTPserver that we will save the tarball into. Finally, the "-b backup.tar" tells ftpbackup that we are copying to the FTP server, and the backup.tar is the name of the file that will be created, containing all of the data that was in /data/web on the local machine.


    To run this script, you need to first make the script executable, using chmod 777 scriptname.sh, then just run /root/scriptname.sh from any directory, or ./scriptname.sh from the /root/ directory.

    The great thing is this can then be put into a cron job, and you have made yourself a reliable automated backup system... for free!

    Remember not to leave the script anywhere on your harddisk that is publicly accessable, as it contains usernames/passwords.

    Jason

  2. #2
    flw
    flw is offline
    Linux Engineer
    Join Date
    Mar 2003
    Location
    U.S.A.
    Posts
    1,025
    Since their is no tut/tip section are you keeping these little nuggets of knowledge on your sys somewhere else? Many times I found short tut's/ tip better than the standard.
    Dan

    \"Keep your friends close and your enemies even closer\" from The Art of War by Sun Tzu\"

  3. #3
    Linux Guru
    Join Date
    Apr 2003
    Location
    London, UK
    Posts
    3,284
    All the little nuggets of knowledge are being put on the forum at the moment, and now being backed up

    I will make a tutorials section soon, should be up by the end of the week or 2 weeks if i add a load of functionality.


    Jason

Posting Permissions

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