SHARE
TWEET

Code Backup Drive

anhkiet2507 Mar 1st, 2019 (edited) 8,113 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. SERVER_NAME="$(ifconfig | grep broadcast | awk {'print $2'} | head -1)" # get IP
  3. # SERVER_NAME="$(ifconfig | grep broadcast | awk {'print $2'} | awk '{if(NR==1) print $0}')"
  4. # SERVER_NAME="$(ifconfig | grep broadcast | awk {'print $2'} | sed -n 1p)"
  5. TIMESTAMP=$(date +"%F")
  6. BACKUP_DIR="/root/backup/$TIMESTAMP"
  7. MYSQL_USER="abc" // Tự thêm USER với PASS MYSQL vào thằng mặt l
  8. MYSQL_PASSWORD="def"
  9. MYSQL=/usr/bin/mysql
  10. MYSQLDUMP=/usr/bin/mysqldump
  11. SECONDS=0
  12. CHECKSQL="mysql"
  13. NGINX="$(ls /etc/ | grep nginx)"
  14. NGINX_DIR="$(nginx -V 2>&1 | grep -o '\-\-conf-path=\(.*conf\)' | grep -o '.*/' | awk -F '=' {'print $NF'})"
  15. HTTPD="$(ls /etc/ | grep -w httpd)"
  16. HTTPD_DIR="$(httpd -S 2>&1 | grep ServerRoot | sed 's/\"//g' | awk {'print $2'})"
  17. LOG_DIR=/var/log/
  18. SENTORA="$(ls /var/ | grep sentora)"
  19. KUSANAGI="$(ls /home/ | grep kusanagi)"
  20. CWP="$(ls /usr/local/ | grep cwpsrv)"
  21. DA="$(ls /usr/local/ | grep directadmin)"
  22. EE="$(ls /etc/ | grep ee)"
  23. VNC_RCLONE="$(rclone config file | grep rclone.conf | sed 's/rclone.conf//')"
  24. VNC_RCLONE_REMOTE="$(cat $VNC_RCLONE/rclone.conf | grep "\[" | sed 's/\[//' | sed 's/\]//')"
  25. mkdir -p "$BACKUP_DIR"
  26.  
  27. if [[ $CHECKSQL == "mysql" ]];
  28.  
  29. then
  30.         mkdir -p "$BACKUP_DIR/mysql"
  31.                 databases=`$MYSQL --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema|mysql)"`
  32.  
  33.         echo "Starting Backup Database";
  34.  
  35.         for db in $databases; do
  36.         $MYSQLDUMP --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db | gzip > "$BACKUP_DIR/mysql/$db.sql.gz"
  37.         done
  38.         echo "Finished";
  39.         echo '';
  40. else
  41.         echo "VPS not install Mysql"
  42. fi
  43.  
  44.  
  45. echo "Starting Backup Website";
  46. # Loop through /home directory
  47. if [ "$SENTORA" = "sentora" ]
  48. then
  49.  
  50.         echo "VPS User sentora ";
  51.         echo "Backup sentora Config";
  52.      for D in /var/sentora/hostdata/*; do
  53.           if [ -d "${D}" ]; then #If a directory
  54.         domain=${D##*/} # Domain name
  55.         echo "- "$domain;
  56.         zip -r $BACKUP_DIR/$domain.zip /var/www/$domain -q -x home/$domain/wp-content/cache/**\* # Không backup cache c?a website
  57.         fi
  58.       done
  59.         cp /root/passwords.txt $BACKUP_DIR/sentora_password
  60.         cp -r /etc/sentora/configs/ $BACKUP_DIR/sentora_config
  61.         cp -r /etc/sentora/configs/apache/ $BACKUP_DIR/apache_config
  62.         cp -r /etc/sentora/configs/proftpd/ $BACKUP_DIR/apache_FTP
  63.         cp -r /var/sentora/logs/ $BACKUP_DIR/logs
  64.         cp -r /var/sentora/vmail/ $BACKUP_DIR/vmail
  65. elif [[ "$KUSANAGI" = "kusanagi" ]]; then
  66.  
  67.         echo "VPS User kusanagi ";
  68.         echo "Backup kusanagi Config";
  69.         sleep 10
  70.         for D in /home/kusanagi/*; do
  71.         if [ -d "${D}" ]; then #If a directory
  72.            domain=${D##*/} # Domain name
  73.                 echo "- "$domain;
  74.            zip -r $BACKUP_DIR/$domain.zip /var/www/$domain -q -x home/$domain/wp-content/cache/**\* # Không backup cache c?a website
  75.          fi
  76.         done
  77.  
  78. elif [[ "$EE" = "ee" ]]; then
  79.  
  80.         echo "VPS User easyengine ";
  81.         echo "Backup easyengine Config";
  82.         sleep 10
  83.         cp /etc/ee/ee.conf $BACKUP_DIR/easyengine
  84.         for D in /var/www/*; do
  85.         if [ -d "${D}" ]; then #If a directory
  86.            domain=${D##*/} # Domain name
  87.                 echo "- "$domain;
  88.            zip -r $BACKUP_DIR/$domain.zip /var/www/$domain -q -x home/$domain/wp-content/cache/**\* # Không backup cache c?a website
  89.          fi
  90.         done
  91. elif [[ "$CWP" = "cwpsrv" ]]; then
  92.  
  93.         echo "VPS User CWP ";
  94.         echo "Backup CWP Config";
  95.         cp /root/.my.cnf $BACKUP_DIR/cwp
  96.         cp /usr/local/apache/conf/ and /usr/local/apache/conf.d/ $BACKUP_DIR/cwp_httpd
  97.         cp /etc/named/ $BACKUP_DIR/named
  98.         cp /var/named/ $BACKUP_DIR/var_named
  99.  
  100.         for D in /home/*; do
  101.         if [ -d "${D}" ]; then #If a directory
  102.                 domain=${D##*/} # Domain name
  103.                 echo "- "$domain;
  104.           zip -r $BACKUP_DIR/$domain.zip /var/www/$domain -q -x home/$domain/wp-content/cache/**\* # Không backup cache c?a website
  105.         fi
  106.         done
  107.  
  108. elif [[ "$DA" = "directadmin" ]]; then
  109.         echo "VPS User directadmin ";
  110.         echo "Backup directadmin Config";
  111.         cp /usr/local/directadmin/conf/mysql.conf $BACKUP_DIR/directadmin
  112.         cp /etc/my.cnf $BACKUP_DIR/directadmin
  113.  
  114.         for D in /home/*; do
  115.         if [ -d "${D}" ]; then #If a directory
  116.                 domain=${D##*/} # Domain name
  117.                 echo "- "$domain;
  118.           zip -r $BACKUP_DIR/$domain.zip /var/www/$domain -q -x home/$domain/wp-content/cache/**\* # Không backup cache c?a website
  119.         fi
  120.         done
  121.  
  122. else
  123.         echo "VPS User Orther Control ";
  124.         echo "Backup Config";
  125.  
  126.         for D in /home/*; do
  127.         if [ -d "${D}" ]; then #If a directory
  128.                 domain=${D##*/} # Domain name
  129.           echo "- "$domain;
  130.                          zip -r $BACKUP_DIR/$domain.zip /var/www/$domain -q -x home/$domain/wp-content/cache/**\* # Không backup cache c?a website
  131.         fi
  132.         done
  133.  
  134.  
  135.         for D in /var/www/*; do
  136.         if [ -d "${D}" ]; then #If a directory
  137.                 domain=${D##*/} # Domain name
  138.          echo "- "$domain;
  139.          zip -r $BACKUP_DIR/source.zip /var/www/html **\* # Không backup cache c?a website
  140.          fi
  141.         done
  142. fi
  143. echo "Finished";
  144. echo '';
  145.  
  146. echo "Starting Backup Server Configuration";
  147. if [ "$NGINX" = "nginx" ] && [ "$HTTPD" = "httpd" ]
  148. then
  149.         echo "Starting Backup nginx proxy, apache backend Configuration";
  150.         cp -r $NGINX_DIR $BACKUP_DIR/nginx
  151.         cp -r $HTTPD_DIR $BACKUP_DIR/httpd
  152.         cp -r $LOG_DIR $BACKUP_DIR/log
  153.         echo "Finished";
  154.         echo '';
  155. elif [ "$NGINX" = "nginx" ];
  156. then
  157.         echo "Starting Backup NGINX Configuration";
  158.         cp -r $NGINX_DIR/ $BACKUP_DIR/nginx
  159.         cp -r $LOG_DIR $BACKUP_DIR/log
  160.         echo "Finished";
  161.         echo '';
  162.  
  163. elif [ "$HTTPD" = "httpd" ];
  164. then
  165.         echo "Starting Backup HTTPD (apache) Configuration";
  166.         cp -r $HTTPD_DIR $BACKUP_DIR/httpd
  167.         cp -r $LOG_DIR $BACKUP_DIR/log
  168.         echo "Finished";
  169.         echo '';
  170. else
  171.         echo "May xai Apache2 tren Ubuntu chu gi. Deo backup cho may nua";
  172. fi
  173.  
  174.  
  175.  
  176. size=$(du -sh $BACKUP_DIR | awk '{ print $1}')
  177. echo "Starting Uploading Backup";
  178.  
  179. for i in $VNC_RCLONE_REMOTE
  180.         do
  181.                 rclone copy $BACKUP_DIR "$i:$SERVER_NAME/$TIMESTAMP" >> /var/log/rclone.log 2>&1
  182.         echo "done upload $i"
  183. done
  184.  
  185. rm -rf $BACKUP_DIR
  186. echo "Finished";
  187. echo '';
  188.  
  189. duration=$SECONDS
  190. echo "Total $size, $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top