Jumat, 07 Januari 2022

Published 23.50 by with 1 comment

Cara Upload Database SIMKES Khanza Otomatis Ke Google Drive Dari Server GhostBSD

Server SIMKES Khanza saya di klinik memakai GhostBSD  21.11.24. Ini server sekaligus klient karena tujuannya buat menghemat listrik biar tidak banyak komputer yang on terus terusan. Untuk jaga-jaga maka databasenya harus saya backup ke lokal dan ke online. Untuk lokal saya taruh di server dan untuk online saya taruh ke Google Drive

Langkah-langkah yang dilakukan:

1. Install rclone

sudo pkg install rclone

Lakukan 

rclone config


sudo nano backup

##this script will backup mysql and upload it to google drive

##directory name

dirname=$1;

##database name

database=$2;

##database username

dbuser=$3;

##database password

dbpass=$4;

## rclone remote name

rcloneRemoteName=$5;

##google drive folder name

gdrivefoldername=$6;

##condition to check folder exist or not

if [ ! -d "$dirname" ]

then

    ##create directory

    mkdir ./$dirname

    ##dump mysql database on server

    mysqldump -u $dbuser -p$dbpass $database | gzip>"./$dirname/$database($(date +\%Y_\%m_\%d_\%H_\%M)).sql.gz"

    ##wait for 10 seconds

    sleep 10

    ##upload it to google drive

    rclone copy "./$dirname/$database($(date +\%Y_\%m_\%d_\%H_\%M)).sql.gz" $rcloneRemoteName:$gdrivefoldername

    ##if folder already exist

else

    ##dump mysql database on server

    mysqldump -u $dbuser -p$dbpass $database | gzip>"./$dirname/$database($(date +\%Y-\%m-\%d-\%H-\%M)).sql.gz"

     ##wait for 10 seconds

    sleep 10

    ##upload it to google drive

    rclone copy "./$dirname/$database($(date +\%Y-\%m-\%d-\%H-\%M)).sql.gz" $rcloneRemoteName:$gdrivefoldername

    ##delete 30 days older file on server to save disk space(this command is optional)

    find ./$dirname -mtime +30 -type f -delete

fi


sudo chmod a+x backup

sudo nano uploaddrive



sudo nano /etc/crontab

0 22             *       *       *        ghostbsd    /home/ghostbsd/uploaddrive

0 10             *       *       *        ghostbsd    /home/ghostbsd/uploaddrive

sudo service cron restart

Referensi: 
https://medium.com/auto-backup-mysql-to-google-drive/auto-backup-mysql-database-from-ubuntu-server-to-google-drive-2020-with-2-easy-steps-ms-techpro-abdb02faed91

      edit

1 komentar:

  1. The Best Slots | Casino Roll
    The best kadangpintar slots at Casino Roll. casino-roll.com If you love table games, to play https://deccasino.com/review/merit-casino/ blackjack, you have 토토 사이트 to bet twice for the dealer to win. The dealer must https://febcasino.com/review/merit-casino/

    BalasHapus