Bash Script Backup Database Mariadb Mysql

بسم الله Bismillah Bash scripting linux untuk backup database dilengkapi dengan log sederhana, untuk memudahkan kita dalam melakukan pemeliharaan database server. Buat File dengan ekstensi *.sh Contoh disini saya membuat file script dengan nama mysqldump.sh nano mysqldump.sh [enter] Scripting Berikut script-nya, bisa disesuaikan dengan lokasi komputer/server masing-masing. #!/bin/sh # script backup database @author: masari CREATED=$(date +'%Y-%m-%d@%H:%M') PATH_BACKUP="/home/"$USER"/backups" MYSQL_USER=root MYSQL_PASS= DATABASE=db_mahasiswa FILENAME="dump-$DATABASE-"$CREATED.sql.gz PATH_FILENAME=$PATH_BACKUP/$CREATED/$FILENAME SERVER=$(uname -mrosn)" | IP: "$(hostname -i) mkdir -p "$PATH_BACKUP/$CREATED" mkdir -p "$PATH_BACKUP/logs" PATH_LOG_FILES=$PATH_BACKUP/"logs" LOG_FILE=$PATH_LOG_FILES/"log_mysqldump".log echo "\n" >> $LOG_FILE echo "---------------------------------------------" >> $LOG_FILE echo "Backup dibuat pada: "$CREATED >> $LOG_FILE echo "Hostname: "$SERVER >> $LOG_FILE echo "---------------------------------------------" >> $LOG_FILE echo "MYSQLDUMP dimulai pada "$(date +'%A, %d-%m-%Y@%T') >> $LOG_FILE echo "---------------------------------------------" >> $LOG_FILE if [ -z "$MYSQL_PASS" ] then mysqldump -u $MYSQL_USER $DATABASE -v 2>> $LOG_FILE | gzip > $PATH_FILENAME else mysqldump -u $MYSQL_USER -p$MYSQL_PASS $DATABASE -v 2>> $LOG_FILE | gzip > $PATH_FILENAME fi echo "---------------------------------------------" >> $LOG_FILE echo "MYSQLDUMP selesai pada "$(date +'%A, %d-%m-%Y@%T') >> $LOG_FILE chown $USER $PATH_FILENAME chown $USER $LOG_FILE echo "Izin berkas telah berhasil diubah!" >> $LOG_FILE echo "=============================================" >> $LOG_FILE exit 0 Simpan script Jangan lupa untuk menyimpan script, dengan perintah editor yang digunakan, disini saya menggunakan editor NANO, jadi saya tinggal menekan tombol CTRL+O [enter] ...

September 9, 2024 · 2 min · Masari

Mysql Dump to Backup Database

بسم الله Bismillah You can accomplish this using the mysqldump command-line function. For example: If it’s an entire DB, then: $ mysqldump -u [uname] -p db_name > db_backup.sql If it’s all DBs, then: $ mysqldump -u [uname] -p --all-databases > all_db_backup.sql If it’s specific tables within a DB, then: $ mysqldump -u [uname] -p db_name table1 table2 > table_backup.sql You can even go as far as auto-compressing the output using gzip (if your DB is very big): ...

September 5, 2024 · 1 min · Masari

Yang Dilakukan Setelah Install Ulang GNU/Linux

Install kebutuhan aplikasi untuk laptop atau pc (developer/linuxer)

August 5, 2020 · 3 min · Masari

MySQL Password error yes!

Your Password does not satisfy the Current Policy Requirements

October 16, 2019 · 1 min · Masari

Install MySQL on CentOS 7

install yum repos as mentioned here on installing mariadb instead of mysql

October 15, 2019 · 1 min · Masari