Cara membuat web host manager sendiri V5 Auto Backup Database ke Google Drive

Me Nime Id
Please wait 0 seconds...
Scroll Down and click on Go to Link for destination
Congrats! Link is Generated

 Oke! Kita tambahkan fitur Auto Backup Database ke Google Drive ke WHM Custom.

Fitur yang Akan Dibuat:

  • Backup database secara manual lewat dashboard.
  • Backup database otomatis setiap hari.
  • Upload hasil backup ke Google Drive.

1️⃣ Buat Google Drive API untuk Upload Backup

Kita akan menggunakan gdrive CLI untuk upload backup ke Google Drive.

🔹 Instalasi gdrive di Server

  1. Download gdrive CLI
    wget -O /usr/local/bin/gdrive https://github.com/prasmussen/gdrive/releases/download/2.1.1/gdrive-linux-x64
    chmod +x /usr/local/bin/gdrive
    
  2. Login ke Google Drive
    Jalankan perintah berikut:
    gdrive about
    
    Ikuti instruksi login untuk mendapatkan token akses.

2️⃣ Buat Script Backup Database

📌 File scripts/backup_database.sh

#!/bin/bash
dbname=$1
backup_dir="/var/backups"
timestamp=$(date +"%Y-%m-%d_%H-%M-%S")
backup_file="$backup_dir/${dbname}_backup_$timestamp.sql"

# Buat folder backup jika belum ada
mkdir -p $backup_dir

# Backup database
mysqldump $dbname > $backup_file

# Upload ke Google Drive (masukkan Folder ID Drive)
folder_id="YOUR_GOOGLE_DRIVE_FOLDER_ID"
gdrive upload --parent $folder_id $backup_file

echo "Backup database $dbname selesai dan diupload ke Google Drive!"

📌 Ganti YOUR_GOOGLE_DRIVE_FOLDER_ID dengan ID folder Google Drive yang akan digunakan.


3️⃣ Tambahkan Fungsi Backup di PHP

📌 File includes/functions.php

<?php
function backupDatabase($dbname) {
    $cmd = "bash ../scripts/backup_database.sh $dbname";
    return shell_exec($cmd);
}
?>

4️⃣ Buat Halaman Backup di Dashboard

📌 File admin/database.php (Tambahkan Bagian Backup Database)

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['backup'])) {
    $dbname = $_POST['dbname'];
    echo backupDatabase($dbname);
}
?>
<h2>Backup Database</h2>
<form method="post">
    <input type="text" name="dbname" placeholder="Nama Database" required><br>
    <button type="submit" name="backup">Backup & Upload ke Google Drive</button>
</form>

🔹 Admin bisa klik tombol backup untuk langsung upload ke Google Drive!


5️⃣ Jadwalkan Backup Otomatis (Cron Job)

Untuk backup otomatis setiap hari, tambahkan cron job di server:

crontab -e

Tambahkan baris berikut (backup setiap jam 02:00 pagi):

0 2 * * * bash /path/to/scripts/backup_database.sh mydatabase

📌 Ganti mydatabase dengan nama database yang ingin di-backup.


🔥 Sekarang WHM Custom Sudah Bisa Backup Database ke Google Drive!

✔ Bisa backup manual dari dashboard.
✔ Bisa backup otomatis setiap hari.
✔ File backup langsung diupload ke Google Drive.

Posting Komentar

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.