My Backup List

Discussion in 'General' started by mphayesuk, Jun 1, 2006.

  1. mphayesuk

    mphayesuk New Member

    I am running Suse 10 64bit and the following list is what I intend to backup on a daily basis for both standard backups and also a disaster recovery.

    Disaster Recovery would be a total system crash and I re-install the system using the same passwords and configuration and then replace all files that I have modified.

    List:

    /etc/passwd
    /etc/shadow
    /etc/group
    /srv/www
    /home/admispconfig
    /etc/apache2
    /etc/proftpd.conf
    /etc/proftpd_ispconfig.conf
    /etc/ssh
    /etc/postfix

    Am I missing anything??

    Thanks
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    I recommend to backup also:

    /var/lib/mysql (your mysql databases)
    /etc/gshadow (dont know if SuSE has this file too)

    If you use mbox format for mail storage, backup also:

    /var/spool/mail
     
  3. mphayesuk

    mphayesuk New Member

    I use maildir so thats not a problem. Thanks for the information.

    Will I need to temp stop any services in order to tar them. Like apache and ispconfig ect.... I thought I read in another post that you have to do some special commands to backup sql databases.

    Thanks
     
  4. falko

    falko Super Moderator ISPConfig Developer

  5. sjau

    sjau Local Meanie Moderator

    If you want to make backups for each individual mysql-db you can use that:

    Just alther the paramaters to what you need.
     
  6. mphayesuk

    mphayesuk New Member

    Falko using the method described in your link, if I am reading it right this would require me to know the names of all the databases so if I have 100 customers each with 2 databases that would mean 200 mysql databases so I would need a method that would just backup all of them.....

    I think the method left by sjau would do this without any human interaction ie if one night I have 200 databases then all of these would get backed up if on the next night there are 201 I dont need to alter any scripts the new database would get backed up. Am I right in thinking this???

    Thanks
     
  7. falko

    falko Super Moderator ISPConfig Developer

    Yes, that right.

    That's also correct.
     
  8. mphayesuk

    mphayesuk New Member

    Do I need to backup /var/lib/mysql if I am going to include the code by sjau in my backup script.
     
  9. falko

    falko Super Moderator ISPConfig Developer

    No, either back up using sjau's way, or back up /var/lib/mysql. Otherwise you back up the same data twice. ;)
     
  10. mphayesuk

    mphayesuk New Member

    Are there any pros and cons of the two methods.

    1) Will backing up /var/lib/mysql using tar and then restoring using tar get anything wrong corrupt data ect...

    2) Which is the best method... what would you recommend.

    Thanks
     
  11. sjau

    sjau Local Meanie Moderator

    It depends on what you want.

    Using falko's method you just create one hugs tar file containing all databases. This is the best if you just want to restore everything again...

    Using my method you create a dump file for each individual database. If you just want to restore one or multiple specific databases, then mine is probably better...

    and in my script alter this:
    To where you want to save your database backups :) You could even add a data tag to the files... or put them into "date" folders... but that can also be done with falko's way...

    Well, basically with both methods you can do everything, it just depends what your primary obeject is... so one or the other method ist just easier to restore, that's the basic difference...
     
  12. mphayesuk

    mphayesuk New Member

    Ok I think your method would suit my needs more... so thanks for the code :D . And all I need to do is tar everything in the mysql_backup folder and then add it to my iso.

    again thanks for the code.
     
  13. mphayesuk

    mphayesuk New Member

    Here is my backup script:

    #!/bin/sh

    #Get the date and create a folder

    prefix=Backup
    suffix=$(date +%d%m%y)
    Today=$prefix.$suffix
    echo "Starting Backup..... Creating directories"
    mkdir /tmp/systembackups/$Today
    mkdir /tmp/systembackups/$Today/mysql_backup
    echo "Direcotries Created"

    #tar customer files
    echo "Starting Tar of Customer Data Files"
    tar -pczf /tmp/systembackups/$Today/customerdata.tar.gz /srv/www
    echo "Completed Tar of Customer Data Files"

    echo "Starting SQL Dump"
    USER=root
    PASSWORD=xxxxxxxxx
    HOST=localhost

    for i in $(echo 'SHOW DATABASES;' | mysql -u$USER -p$PASSWORD -h$HOST|grep -v '^Databases$'); do
    mysqldump \
    -u$USER -p$PASSWORD -h$HOST \
    -Q -c -C --add-drop-table --add-locks --quick --lock-tables \
    $i > /tmp/systembackups/$Today/mysql_backup/$i.sql;
    done;

    echo "Completed SQL Dump"

    #tar system files
    echo "Starting Tar of System Files"
    tar -pczf /tmp/systembackups/$Today/systemfiles.tar.gz /home/admispconfig /etc/apache2 /etc/proftpd.conf /etc/proftpd_ispconfig.conf /etc/ssh /etc/postfix
    echo "Completed Tar of System Files"

    #tar password files
    echo "Starting Tar of Password Files"
    tar -pczf /tmp/systembackups/$Today/passwords.tar.gz /etc/passwd /etc/shadow /etc/group
    echo "Completed Tar of Password Files"

    #make the iso
    echo "Starting to Compile ISO"
    mkisofs -r -o /tmp/systembackups/$Today/backup.iso /tmp/systembackups/$Today/customerdata.tar.gz /tmp/systembackups/$Today/systemfiles.tar.gz /tmp/systembackups/$Today/passwords.tar.gz
    echo "Completed ISO Compile"
    #blank the cdrw

    #cdrecord /dev/cdrom blank disk

    #write the disk
    echo "Attemping to Write the Disk"
    growisofs -Z /dev/dvdrecorder=backup.iso
    echo "Completed Writting Disk"

    ****************************************
    I get 2 errors with this:

    1)mysqldump: Got error: 1049: Unknown database 'Database' when selecting the database

    and

    2) Attemping to Write the Disk
    :-( unable to open64("backup.iso",O_RDONLY): No such file or directory
    Completed Writting Disk

    The second one is the same type of problem that I have posted in the technical forum... can anyone help with this.

    Thanks
     
  14. sjau

    sjau Local Meanie Moderator

    The mysql backup script works for me fine....
    Maybe that space is needed in the shell script
    Code:
    #!/bin/bash
    # Remove old files
    rm -f /mysql_backup/*
    
    #Dump new files
    USER=root
    PASSWORD=***********
    HOST=localhost
    
    for i in $(echo 'SHOW DATABASES;' | mysql -u$USER -p$PASSWORD -h$HOST|grep -v '^Database$'); do
      mysqldump                                                     \
      -u$USER -p$PASSWORD -h$HOST                                   \
      -Q -c -C --add-drop-table --add-locks --quick --lock-tables   \
      $i > /mysql_backup/$i.sql;
    done;
    
     
  15. mphayesuk

    mphayesuk New Member

    Thanks for the post I have found the problem... I cant type...:D I had put databases instead of database, so that has fixed part one of my problems, does anyone have any comments about my second problem;

    :-( unable to open64("backup.iso",O_RDONLY): No such file or directory

    Thanks
     
  16. sjau

    sjau Local Meanie Moderator

    Could the CD/DVD is be mounted as read only?
     
  17. alexnz

    alexnz New Member

    this is a fantastic thread on how too backup files with ipconfig- another question

    how do i setup this script so it runs every 24hours at say 11:59pm at night?
     
  18. sjau

    sjau Local Meanie Moderator

    Add a cron :)

    In shell login as root

    create a .txt file (I named mine cron.txt)

    Add the following code

    Code:
    # Run Backup Script
    59 23 * * * * sh /path/to/shellscript
    
    and if you want to have the output emailed to you (good for checking) do this:

    Code:
    # Run Backup Script
    59 23 * * * * sh /path/to/shellscript | /usr/bin/mail -s "Cron Backup" [email protected]
    
    (The script above is 1 line)

    Then save and exit the file.

    And enter the following command in bash:

    This will overwrite your root crontab with the cron.txt

    Now check whether it was added correctly:
    P.S.: Before you add a cron like that do a check whether there is already some cronjob ^^
     
  19. mphayesuk

    mphayesuk New Member

    Perhaps the cd/dvd drive is being mounted as read only, so how do I check it and how do I mount it as read and write.

    Thanks
     
  20. till

    till Super Moderator Staff Member ISPConfig Developer

    I'am not sure if you can simply mount a CD-RW for writing. I guess you might have to use a CD / DVD buring application. But I never tried to burn a DVD on the commandline in linux.
     

Share This Page