kedar_dave9002
New member
How to take auto backup at certain time daily in solo for database ?
#!/bin/bash
# Set database credentials
USER="username"
PASSWORD="password"
HOST="localhost"
DB_NAME="database_name"
# Set backup directory and filename
BACKUP_DIR="/path/to/backup/directory"
DATE=$(date +%Y-%m-%d-%H-%M-%S)
BACKUP_FILENAME="$DB_NAME-$DATE.sql"
# Create backup directory if it doesn't exist
if [ ! -d "$BACKUP_DIR" ]; then
mkdir -p "$BACKUP_DIR"
fi
# Use mysqldump to create backup
mysqldump --user=$USER --password=$PASSWORD --host=$HOST $DB_NAME > $BACKUP_DIR/$BACKUP_FILENAME
# Print success message
echo "Database backup created: $BACKUP_DIR/$BACKUP_FILENAME"
[mysqldump]
user=username
password=password
#!/bin/bash
# Set database credentials
HOST="localhost"
DB_NAME="database_name"
# Set backup directory and filename
BACKUP_DIR="/path/to/backup/directory"
DATE=$(date +%Y-%m-%d-%H-%M-%S)
BACKUP_FILENAME="$DB_NAME-$DATE.sql"
# Create backup directory if it doesn't exist
if [ ! -d "$BACKUP_DIR" ]; then
mkdir -p "$BACKUP_DIR"
fi
# Use mysqldump to create backup
mysqldump --defaults-file=~/.my.cnf --host=$HOST $DB_NAME > $BACKUP_DIR/$BACKUP_FILENAME
# Print success message
echo "Database backup created: $BACKUP_DIR/$BACKUP_FILENAME"