Welcome to Centmin Mod Community
Register Now

Sysadmin Sharing a few of my scripts

Discussion in 'System Administration' started by denellum, Dec 12, 2017.

  1. denellum

    denellum Member

    88
    21
    8
    May 11, 2016
    Dallas
    Ratings:
    +31
    Local Time:
    12:36 PM
    1.13.8
    10.1.29
    First off : If this isn't allowed please feel free to delete!

    Long story short : I needed a couple backup scripts created so I can send my data to backblaze b2 : Link via rclone : Link. So I created a couple, the reason they are split up is because my systems are set up with 2 servers, 1 "web server" and 1 "database server"... Tell me what you think and everyone is welcome to use them :


    Web Server:

    Cron :
    Code:
    #Website Backup
    0 0,8,16 * * * /bin/sh /usr/local/scripts/root/backup_websites.sh 2>/dev/null
    #Move Backups to B2
    30 23 * * * /bin/sh /usr/local/scripts/root/move_backups.sh 2>/dev/null
    
    backup_websites.sh
    Code:
    !/bin/bash
    # Variables
            domains_path="/home/nginx/domains"
            date=$(date +"%b-%d-%Y")
    # Array
            array=(`ls -I demodomain.com $domains_path`)
    # Tar the directories in their respected directories
            for i in "${array[@]}";
            do tar -czf $domains_path/$i/backup/$date-$i.tar.gz $domains_path/$i/public;
            done
    # Delete files older than 3 days
            find $domains_path/$i/backup/*.tar.gz -mtime +3 -exec rm {} \;
    
    move_backups.sh
    Code:
    #!/bin/bash
    # Variables
            date=$(date +"%b-%d-%Y")
            domains_path="/home/nginx/domains"
            bucket="web01-mycompany"
    # Array
            array=(`ls -I demodomain.com $domains_path`)
    # Move to spaces
            for i in "${array[@]}"; do rclone sync $domains_path/$i/backup/$date-$i.tar.gz "bucketname":$bucket/$date/ ;done
    

    Database Server:

    Cron

    Code:
    #Database Backup
    0 0,8,16 * * * /bin/sh /usr/local/scripts/root/mysql_backup.sh 2>/dev/null
    #Move Backups to B2
    30 23 * * * /bin/sh /usr/local/scripts/root/move_backups.sh 2>/dev/null
    

    mysql_backup.sh

    Code:
    #!/bin/bash
    # Database info
            database=( database1 database2 database3 database4 database5)
    # Variables
            date=$(date +"%b-%d-%Y")
            backup_path="/root/backups/$date"
    # Set default file permissions
            umask 177
    # Make the directory
            mkdir $backup_path
    # Dump database into SQL file
            for i in "${database[@]}";
            do
            mysqldump -uroot $i > $backup_path/$i.sql;
            done
    # Delete files older than 3 days
            find $backup_path/*sql -mtime +3 -exec rm {} \;
    

    move_backups.sh

    Code:
    #!/bin/bash
    # Variables
            date=$(date +"%b-%d-%Y")
            backup_path="/root/backups/$date/"
            bucket="db01-mycompany"
    # Move to spaces
            for i in $backup_path/*.sql; do rclone sync $i "bucketname":$bucket/$date/ ;done
    

     
    • Winner Winner x 2
    • Informative Informative x 2
  2. eva2000

    eva2000 Administrator Staff Member

    36,809
    8,060
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,414
    Local Time:
    4:36 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
..