Simple script for ispConfig software backup

Discussion in 'Programming/Scripts' started by maxlinux, Aug 15, 2019.

  1. maxlinux

    maxlinux New Member

    Fell free to modify as you need. It works in ubuntu and debian distros.

    ---------------------------
    #!/bin/bash
    DATE=$(date +"%Y-%m-%d_%H-%M-%S")
    NAME=$(hostname)
    PASS=$(cat /etc/mysql/debian.cnf | grep "password" | head -n1 | tr -d ' ' | cut -d "=" -f2)
    mkdir ispconfig_"$NAME"_"$DATE"
    cd ispconfig_"$NAME"_"$DATE"
    tar zcvf etc.tar.gz /etc
    tar zcvf ispconfig_software.tar.gz /usr/local/ispconfig
    mysqldump -uroot -p$PASS dbispconfig > ispconfig_db_backup.sql
    ---------------------------
     
  2. Taleman

    Taleman Well-Known Member HowtoForge Supporter

    I think you should add a cd to suitable base directory before the mkdir ispconfig_"$NAME"_"$DATE"
     
  3. maxlinux

    maxlinux New Member

    Yes you are rigth.
    Do you know witch database table is stored the path of backup? (/var/backup as default, but the user can change it)
    I can do a query to have this path and cd to the bakup folder after create the new ispconfig_"$NAME"_"$DATE"
     
  4. maxlinux

    maxlinux New Member

    Here an update:
    --------------------
    #!/bin/bash

    DATE=$(date +"%Y-%m-%d_%H-%M-%S")
    NAME=$(hostname)
    PASS=$(cat /etc/mysql/debian.cnf | grep "password" | head -n1 | tr -d ' ' | cut -d "=" -f2)
    BDir=$(mysql -u root -p"$PASS" -D dbispconfig -e "SELECT config FROM server WHERE server.server_id=1" | sed 's|\\n|\n|g' | grep "backup_dir=" | sed 's|backup_dir=||')
    cd $BDir
    mkdir ispconfig_"$NAME"_"$DATE"
    cd ispconfig_"$NAME"_"$DATE"
    tar zcvf etc.tar.gz /etc
    tar zcvf ispconfig_software.tar.gz /usr/local/ispconfig
    mysqldump -uroot -p$PASS dbispconfig > ispconfig_db_backup.sql
    cd ~
    --------------------
    save as ispSWbackup.sh

    install it in /usr/local/bin with:
    $ sudo install ispSWbackup.sh /usr/local/bin

    Edit: removed temporal file
     
    Last edited: Aug 15, 2019

Share This Page