User Tools

Site Tools


mysql_backup
  • CREATE DATABASE hotspot_user_db ;
  • CREATE USER 'wififreeuser'@'localhost' IDENTIFIED BY 'Hell0Dh@ka';
  • GRANT ALL PRIVILEGES ON hotspot_user_db.* TO 'wififreeuser'@'localhost';
  • FLUSH PRIVILEGES;
  • exit

* root@xxx:/usr/local/bin # cat bvisionDB.sh

  • #!/bin/bash
  • # Database credentials
  • user=“root”
  • password=“xxx#i”
  • host=“localhost”
  • #db_name=“radius”
  • #
  • # Other options
  • backup_path=“/backup/bvision_DB”
  • date=$(date +“%b-%d-%Y”)
  • #
  • # Set default file permissions
  • umask 177
  • #
  • # Lock the database and sleep in background task
  • mysql –user=$user –password=$password -e “FLUSH TABLES WITH READ LOCK; DO SLEEP(3600);” &
  • sleep 3
  • #
  • # Dump database into SQL file
  • mysqldump –user=$user –password=$password –host=$host –all-databases | gzip > $backup_path/BV-DB_FULLBK-$date.sql.gz
  • #
  • # When finished, kill the previous background task to unlock
  • kill $! 2>/dev/null
  • wait $! 2>/dev/null
  • echo “Finished export, and unlocked !”
  • ###############################################################################
mysql_backup.txt · Last modified: 2023/03/06 11:31 by 127.0.0.1