Welcome to Centmin Mod Community
Become a Member

Need Amazon s3 Backup for Centminmod

Discussion in 'Add Ons' started by brijendrasial, Mar 27, 2018.

  1. brijendrasial

    brijendrasial New Member

    8
    3
    3
    Mar 21, 2018
    Ratings:
    +7
    Local Time:
    5:44 PM
    1.13.9
    10.0.22-MariaDB
    Hello,

    Is there any free or paid script available for it?
     
  2. wmtech

    wmtech Member

    69
    19
    8
    Jul 22, 2017
    Ratings:
    +44
    Local Time:
    2:14 PM
  3. eva2000

    eva2000 Administrator Staff Member

    36,422
    7,994
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,308
    Local Time:
    10:14 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    For Centmin Mod only official mysql database only backup script is dbbackup.sh for Premium members MariaDB - dbbackup.sh - quick mysql database backups for Centmin Mod stack. Plan is eventually to extend it for site data/files but for now it's mysql only.

    There maybe other member created backup scripts around if folks may want to share. You can also search the forums as there's a few discussions here for backup scripts. Or write your own addon/script. Some info on config files at Centmin Mod Configuration Files - CentminMod.com LEMP Nginx web stack for CentOS. Below migrating data guides may also give you more insight into Centmin Mod directory/file structure too.

    For moving site data there's 2 general guides where the principles & steps of backing up and moving data is the same just slightly different for
    1. Moving Centmin Mod site data to another Centmin Mod server
    2. Moving cPanel/WHM site data to Centmin Mod server
    Those guides move alot more than just the site(s) in question but config files etc. You can use your own best judgement as to the config files you want to backup.
     
  4. brijendrasial

    brijendrasial New Member

    8
    3
    3
    Mar 21, 2018
    Ratings:
    +7
    Local Time:
    5:44 PM
    1.13.9
    10.0.22-MariaDB
    Ok so I am using below script for database and files backup and sending it to amazon s3

    Code:
    #!/bin/bash
    
    ## Email Variables
    EMAILDATE=`date --date="today" +%y-%m-%d`
    EMAIL="[email protected]"
    
    SUBJECT="MOBI Backup Script Started! - "$EMAILDATE
    EMAILMESSAGE="/tmp/emailmessage1.txt"
    echo "Just to let you know that the backup script has started."> $EMAILMESSAGE
    /usr/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
    
    # Set up the variables
    ### The URI of the S3 bucket.
    S3URI='YourBucketName'
    
    ### An array of directories you want to backup (I included a few configuration directories to).
    DirsToBackup=(
    '/home/nginx/domains/yourdomain.com/public'
    )
    
    ### The databases you want to backup
    DBsToBackup=(
    ''
    )
    
    ### The directory we're going to story our backups in on this server.
    TmpBackupDir='/home/nginx/domains/yourdomain.com/backup'
    
    
    ## The MySQL details
    MySQLDetails[0]='' # MySQL Host
    MySQLDetails[1]='' # User
    MySQLDetails[2]='' # Password
    
    
    ## The expiry dates of the backups
    ### Only store 0 days of backups on the server.
    ### Changed to 0 days to not fill the server with unneccessary backups
    Expiry[0]=`date --date="today" +%y-%m-%d`
    
    ### Only store 2 weeks worth of backups on S3
    Expiry[1]=`date --date="2 weeks ago" +%y-%m-%d`
    
    ### Using ExpiryDayOfMonth to skip first day of the month when deleting so monthly backups are kept on s3
    ExpiryDayOfMonth=`date --date="2 weeks ago" +%d`
    
    ### Todays date.
    TodayDate=`date --date="today" +%y-%m-%d`
    
    ## Finally, setup the today specific variables.
    Today_TmpBackupDir=$TmpBackupDir'/'$TodayDate
    
    
    # Start backing up things.
    
    ## Check we can write to the backups directory
    if [ -w "$TmpBackupDir" ]
    then
      # Do nothing and move along.
        echo 'Found and is writable:  '$TmpBackupDir
    else
        echo "Can't write to: "$TmpBackupDir
        exit
    fi
    
    ## Make the backup directory (Also make it writable)
    echo ''
    echo 'Making Directory: '$Today_TmpBackupDir
    mkdir $Today_TmpBackupDir
    chmod 0777 $Today_TmpBackupDir
    
    ## GZip the directories and put them into the backups folder
    echo ''
    for i in "${DirsToBackup[@]}"
    do
        filename='dir-'`echo $i | tr '/' '_'`'.tar.gz'
        echo 'Backing up '$i' to '$Today_TmpBackupDir'/'$filename
        tar -czpPf $Today_TmpBackupDir'/'$filename $i
    done
    
    ## Backup the MySQL databases
    echo ''
    for i in "${DBsToBackup[@]}"
    do
        filename='mysql-'$i'.sql'
        echo 'Dumping DB '$i' to '$Today_TmpBackupDir'/'$filename
        mysqldump -h "${MySQLDetails[0]}" -u "${MySQLDetails[1]}" -p"${MySQLDetails[2]}" $i > $Today_TmpBackupDir'/'$filename
        tar -czpPf $Today_TmpBackupDir'/'$filename'.tar.gz' $Today_TmpBackupDir'/'$filename
        rm -R $Today_TmpBackupDir'/'$filename
    done
    
    ## Alert admin that backup complete, starting sync
    SUBJECT="MOBI Backup Complete, Starting Sync! - "$EMAILDATE
    EMAILMESSAGE="/tmp/emailmessage2.txt"
    echo "Just to let you know that the backup script has finished and we're starting sync to s3 now."> $EMAILMESSAGE
    /usr/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
    
    ## Sending new files to S3
    echo ''
    echo 'Syncing '$Today_TmpBackupDir' to '$S3URI$TodayDate'/'
    s3cmd put --recursive $Today_TmpBackupDir $S3URI
    if [ $? -ne 0 ]; then
        SUBJECT="s3cmd put failed on MOBI"
        EMAILMESSAGE="/tmp/emailmessage3.txt"
            echo "Just to let you know that the s3cmd put of '$Today_TmpBackupDir' failed."> $EMAILMESSAGE
            echo "You should check things out immediately." >>$EMAILMESSAGE
        /usr/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
    fi
    
    # Cleanup.
    echo ''
    echo 'Removing local expired backup: '$TmpBackupDir'/'${Expiry[0]}
    rm -R $TmpBackupDir'/'${Expiry[0]}
    
    if [ "$ExpiryDayOfMonth" != '01' ]; then
        echo 'Removing remote expired backup: '$S3URI${Expiry[1]}'/'
        s3cmd del $S3URI${Expiry[1]}'/' --recursive
    else
        echo 'No need to remove backup on the 1st'
    fi
    
    echo 'Making '$Today_TmpBackupDir' permissions 0755'
    chmod 0755 $Today_TmpBackupDir
    
    echo 'All Done! Yay! (",)'
    
    ## Notify admin that the script has finished
    SUBJECT="MOBI S3 Sync Complete! - "$EMAILDATE
    EMAILMESSAGE="/tmp/emailmessage4.txt"
    echo "Just to let you know that the s3 sync has now completed."> $EMAILMESSAGE
    /usr/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
    
    
    ## Email Report of What Exists on S3 in Today's Folder
    exec 1>'/tmp/s3report.txt'
    s3cmd ls s3://YourBucketName/$TodayDate/
    
    SUBJECT="S3 Backup Report of MOBI: "$TodayDate
    EMAILMESSAGE="/tmp/s3report.txt"
    /usr/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
    
    
     
    Last edited: Mar 30, 2018
    • Like Like x 1
    • Winner Winner x 1
    • Informative Informative x 1
  5. eva2000

    eva2000 Administrator Staff Member

    36,422
    7,994
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,308
    Local Time:
    10:14 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
  6. brijendrasial

    brijendrasial New Member

    8
    3
    3
    Mar 21, 2018
    Ratings:
    +7
    Local Time:
    5:44 PM
    1.13.9
    10.0.22-MariaDB
    Ok thanks changed :)
     
..