Don ta atomatik backup
ko MySQL
bayanan MariaDB yau da kullun ta amfani da MySQLDump, zaku iya bin matakan da ke ƙasa:
Ƙirƙiri fayil ɗin rubutun madadin
Ƙirƙiri fayil ɗin rubutun(misali, backup.sh
) don ƙunshe da umarnin madadin. Bude editan rubutu kuma ƙara umarni masu zuwa zuwa fayil ɗin rubutun:
#!/bin/bash
# Replace the database connection information
DB_USER="username"
DB_PASSWORD="password"
DB_NAME="database_name"
# Path to the backup directory
BACKUP_DIR="/path/to/backup/directory"
# Create a backup file name with date format
BACKUP_FILE="$BACKUP_DIR/backup-$(date +%Y-%m-%d).sql"
# Use mysqldump command to backup the database
mysqldump -u$DB_USER -p$DB_PASSWORD $DB_NAME > $BACKUP_FILE
# Print a completion message when the backup is done
echo "Backup completed: $BACKUP_FILE"
Ajiye fayil ɗin rubutun kuma tabbatar yana da izini masu aiwatarwa. Don yin wannan, gudanar da umarni mai zuwa:
chmod +x backup.sh
Saita aikin madadin atomatik
Yi amfani da cron
jadawali don saita aikin madadin atomatik na yau da kullun. Bude jadawalin cron ta hanyar gudanar da umarni:
crontab -e
Ƙara layin da ke gaba zuwa fayil ɗin cron don saita aikin madadin yau da kullum a 2 AM:
0 2 * * * /path/to/backup.sh
Ajiye kuma rufe cron
fayil ɗin jadawalin.
Za a aiwatar da rubutun backup.sh
yau da kullun a 2 AM, kuma zai adana MySQL
bayanan ko MariaDB zuwa fayil ɗin th e backup-YYYY-MM-DD.sql
a cikin ƙayyadadden jagorar.
Lura cewa a cikin rubutun, kuna buƙatar maye gurbin username
, password
, da kuma database_name
tare da ainihin bayanan shiga da sunan bayanai. Hakazalika, canza /path/to/backup/directory
zuwa ainihin hanyar ajiyar ajiyar ajiya akan tsarin ku.