Auto-Backup Procedure saves all the data in a external Disk

Discussion in 'Installation/Configuration' started by vaio1, Oct 27, 2008.

  1. vaio1

    vaio1 Member

    Hi guys,

    I have tried to create an automatic way to backup all the ISPConfig configurations, mails, and server configurations. How to improve it? Any idea?

    Code:
    #!/bin/bash
    
    DATE=`date +%F`
    
    COPY_TO=/mnt/mydisk
    USER=root
    PASSWORD=***** [YOURPASSWORD]
    HOST=localhost
    
    mount /dev/sdb1 /mnt/mydisk/
    
    echo "";
    echo "************************************";
    echo "       ISP CONFIG BACKUP";
    echo "************************************";
    echo "";
    
    mkdir -p $COPY_TO/ispconfig/$DATE
    
    echo "Wait a moment please...";
    
    echo "1. Make a backup of /var/spool/mail";
    /etc/init.d/postfix stop
    cd /var/spool
    tar -czf $COPY_TO/ispconfig/$DATE/mail.tar.gz mail
    
    echo "2. Copy the passwd file";
    cp /etc/passwd $COPY_TO/ispconfig/$DATE
    
    echo "3. Copy the shadow file";
    cp /etc/shadow $COPY_TO/ispconfig/$DATE
    
    echo "4. Copy the group files";
    cp /etc/group $COPY_TO/ispconfig/$DATE
    
    echo "5. Copy the Vhosts_ispconfig.conf file";
    cp /etc/httpd/conf/vhosts/Vhosts_ispconfig.conf $COPY_TO/ispconfig/$DATE
    
    echo "6. Copy the local-host-names file";
    cp /etc/postfix/local-host-names $COPY_TO/ispconfig/$DATE
    
    echo "7. Copy the postfix/virtusertable file";
    cp /etc/postfix/virtusertable $COPY_TO/ispconfig/$DATE
    
    echo "8. Copy the named.conf file";
    cp /var/named/chroot/etc/named.conf $COPY_TO/ispconfig/$DATE
    
    echo "9. Copy the proftpd.conf file";
    cp /etc/proftpd.conf $COPY_TO/ispconfig/$DATE
    
    echo "10. Copy the proftpd_ispconfig.conf file";
    cp /etc/proftpd_ispconfig.conf $COPY_TO/ispconfig/$DATE
    
    echo "11. Backup of the ISPConfig Databse";
    mysqldump \
            -u$USER -p$PASSWORD -h$HOST \
            -Q -c -C --add-drop-table --add-locks --quick --lock-tables \
            db_ispconfig | gzip --best -c > $COPY_TO/ispconfig/$DATE/db_ispconfig.sql.gz;
    
    
    echo "Restart Postfix"
    /etc/init.d/postfix start
    
    echo "End of procedure";
    
    
     
  2. sjau

    sjau Local Meanie Moderator

    why don't you start postfix again after you have copied the spool?
     
  3. vaio1

    vaio1 Member

    Look at the bottom of the file ;)
     
  4. sjau

    sjau Local Meanie Moderator

    yeah, but do do you start it at the end of the backup script and not when copying spool is finished? That's just what wonders me ;)
     
  5. vaio1

    vaio1 Member

    oh I have understood!
    Thanks any other suggestions?
     
  6. make-fun

    make-fun Member

    1. curlftpfs - to mount a ftp host as a local directory (if no external HD)
    2. DATE=$(date +%d) - so you'll get 01-31 dirs and have older ones overwritten automatically
    3. at the end
      Code:
      if [ $(date +%d) == 01 ]; then
        echo "Monthly Backup"
        mkdir -p $COPY_TO/ispconfig/$(date --date=-1day +%b) / name of previous month e.g. Oct
        cp mkdir -p $COPY_TO/ispconfig/$DATE $COPY_TO/ispconfig/$(date +%b)
      fi
      So you keep a monthly backup for up to 12 month Jan-Dez and have older ones overwritten automatically
     
  7. sjau

    sjau Local Meanie Moderator

    Well, I am just wondering as to why do start the server at the end again and not at the end of the actual operation :) You may have good reasons for that and I'm curious so to what those are :)
     

Share This Page