Last active
August 10, 2024 07:56
-
-
Save masudur-rahman-niloy/2644c6739c5ba239287b4daa2d815f4f to your computer and use it in GitHub Desktop.
bash script to backup mysql database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Database credentials | |
DB_USER="your_username" # change this | |
DB_PASSWORD="your_password" # change this | |
DB_NAME="your_database_name" # change this | |
# Backup directory | |
BACKUP_DIR="/path/to/backup/directory" # change this | |
# Timestamp (to create unique backup filenames) | |
TIMESTAMP=$(date +"%Y%m%d%H%M%S") | |
# Create backup directory if it doesn't exist | |
mkdir -p $BACKUP_DIR | |
# Backup the MySQL database | |
mysqldump -u$DB_USER -p$DB_PASSWORD $DB_NAME > $BACKUP_DIR/$DB_NAME-$TIMESTAMP.sql | |
echo "Backup completed: $BACKUP_DIR/$DB_NAME-$TIMESTAMP.sql" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
installing mysql client is necessary. see this link for installing mysql-client
https://www.bytebase.com/blog/how-to-install-mysql-client-on-mac-ubuntu-centos-windows/