Jump to content

bash script for backup


abazoskib

Recommended Posts

i want my bash script to check if a lock file exists, if it exists, the script should keep checking till the lock file is gone, and then proceed. so far, ive made it so the script exits if the lock file is found. whats the change i need to make? i know i need a while loop, but im still learning bash syntax so hopefully someone could shed some light on this topic for me

 

if [ -f /usr/xxxx/xxxx.lock ]
then
        exit 1
else
        #!/bin/sh
        DATE=`date +%Y-%m-%e`
        mysqldump -uxxx -pXXXXX XXX_db xx_tbl > /ebs/MYSQL_BACKUPS/xx_$DATE.sql
        mysqldump -uxxx -pXXXXX XXX_db xx_tbl > /ebs/MYSQL_BACKUPS/xx_$DATE.sql
        cd /ebs/MYSQL_BACKUPS

        tar -czf mysql_backup_$DATE.sql.tar.gz  xx_$DATE.sql xx_$DATE.sql
        rm -f *.sql
fi

Link to comment
Share on other sites

Not tested.

 

#!/bin/sh

while true ; do
  attemptbackup;
done

function attemptbackup() {
  if [ -f /usr/xxxx/xxxx.lock ]
  then
    return
  else
    DATE=`date +%Y-%m-%e`
    mysqldump -uxxx -pXXXXX XXX_db xx_tbl > /ebs/MYSQL_BACKUPS/xx_$DATE.sql
    mysqldump -uxxx -pXXXXX XXX_db xx_tbl > /ebs/MYSQL_BACKUPS/xx_$DATE.sql
    cd /ebs/MYSQL_BACKUPS

    tar -czf mysql_backup_$DATE.sql.tar.gz  xx_$DATE.sql xx_$DATE.sql
    rm -f *.sql
  fi
  exit
}

Link to comment
Share on other sites

the lock file is created by another script while running. the script that creates the file also removes the file at the end of completion. and the reason i check for it is because the script that creates the script works hourly, and adds to the tables i am backing up. mysqldump locks the tables, so i cant risk losing data.

Link to comment
Share on other sites

  • 3 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.