Scripts for backup

Emerson Tiamzon

Posted at April 09, 2024 04:04 pm. Last updated at February 10, 2025 11:02 am
Backup And Restore

Backup Folder and Files Script

 

#!/bin/bash

folderPath=/var/www/
backupFolder=/mnt/backup/file/
getDate=$(date '+%Y%m%d_%H%M')

for folder in $folderPath*
do
        folderName=$(basename $folder)

# EXCLUDE Folders
                if [[ $folderName == weightlossdrug.store || $folderName == backup ]]
                then
                      echo $folderName" Ignored"
                else
                       cd $folderPath && zip -r $backupFolder/$folderName-$getDate.zip $folderName
                fi


done

 

Backup Database Script

#!/bin/bash

hostName=$(hostname)
backupDir=/mnt/backup/database/

cmdDump="/usr/bin/mysqldump --skip-extended-insert --force"
cmdSQL=/usr/bin/mysql

getDate=$(date '+%Y%m%d_%H%M')


# Get a list of all databases
Databases=$(echo "SHOW DATABASES" | $cmdSQL -h localhost)


for db in $Databases; do
        date=`date`
        file="$backupDir/$hostName-$db-$getDate.sql.gz"
        if [[ $db == weightlossdrug ]]
        then
                echo "Backing up '$db' from '$hostName' on '$date' to: "
                echo "$file"

                $cmdDump -h localhost $db | gzip > $file
        fi
done

 

Other script

#!/bin/bash

hostName=$(hostname)
backupDir=/mnt/remote_backup/database/


cmdDump="/usr/bin/mysqldump "
cmdSQL=/usr/bin/mysql

getDate=$(date '+%Y%m%d_%H%M')


# Get a list of all databases
Databases=$(echo "SHOW DATABASES" | $cmdSQL -h (host) -u (user) -p(password)


for db in $Databases; do
        date=`date`
        file="$backupDir/$hostName-$db-$getDate.sql.gz"

          if [[ $db == *"awm"* ]]
             then

                echo "Backing up '$db' from '$hostName' on '$date' to: "
                echo "$file"

               $cmdDump --user=(user) --password=(Password) --lock-tables=false  $db        | gzip > $file

        fi
done

 

For easy reading here

 

 

You must be logged in to comment about this post.Click here to login.

Comments

No results found.
Search