Struktur aplikasi:
/var/www/gallery/Lychee
Dokumentasi ini mencakup:
- Backup database
- Backup file aplikasi dan foto
- Upload ke Google Drive
- Otomatisasi backup
- Restore dari file lokal
- Restore dari Google Drive
- Verifikasi dan troubleshooting
I. Backup Lychee
1. Backup Database
1.1 Cek Nama Database
cat /var/www/gallery/Lychee/.env | grep DB_DATABASE
Contoh hasil:
DB_DATABASE=lychee_db
1.2 Dump Database
mysqldump -u root -p lychee_db > /root/lychee-db-$(date +%F).sql
File hasil:
/root/lychee-db-YYYY-MM-DD.sql
2. Backup File Aplikasi dan Foto
Karena Lychee menyimpan foto di dalam direktori aplikasinya, backup seluruh folder:
tar -czf /root/lychee-files-$(date +%F).tar.gz /var/www/gallery/Lychee
File hasil:
/root/lychee-files-YYYY-MM-DD.tar.gz
Backup ini mencakup:
- File aplikasi
- Folder foto
- Storage internal
- File konfigurasi
.env
3. Upload Backup ke Google Drive
Pastikan rclone sudah terkonfigurasi dan dapat mengakses remote gdrive.
Verifikasi koneksi:
rclone lsd gdrive:
Upload database:
rclone copy /root/lychee-db-YYYY-MM-DD.sql gdrive:backup-lychee
Upload file aplikasi:
rclone copy /root/lychee-files-YYYY-MM-DD.tar.gz gdrive:backup-lychee
Verifikasi file di Google Drive:
rclone ls gdrive:backup-lychee
Backup sekarang tersimpan secara lokal dan offsite.
II. Otomatisasi Backup
1. Buat Script Backup
nano /root/backup-lychee.sh
Isi:
#!/bin/bash
DATE=$(date +%F)
DB_NAME="lychee_db"
APP_DIR="/var/www/gallery/Lychee"
BACKUP_DIR="/root"
# Backup Database
mysqldump $DB_NAME > $BACKUP_DIR/lychee-db-$DATE.sql
# Backup Files
tar -czf $BACKUP_DIR/lychee-files-$DATE.tar.gz $APP_DIR
# Upload ke Google Drive
rclone copy $BACKUP_DIR/lychee-db-$DATE.sql gdrive:backup-lychee
rclone copy $BACKUP_DIR/lychee-files-$DATE.tar.gz gdrive:backup-lychee
# Hapus backup lokal lebih dari 7 hari
find $BACKUP_DIR -name "lychee-*" -mtime +7 -delete
2. Beri Permission Eksekusi
chmod +x /root/backup-lychee.sh
3. Tambahkan Cron Job
crontab -e
Tambahkan:
30 2 * * * /root/backup-lychee.sh >> /root/backup-lychee.log 2>&1
Backup akan berjalan otomatis setiap pukul 02:30.
III. Restore Lychee
A. Restore dari File Lokal
1. Restore Database
Masuk ke MySQL:
mysql -u root -p
Jika database belum ada:
CREATE DATABASE lychee_db;
EXIT;
Import database:
mysql -u root -p lychee_db < /root/lychee-db-YYYY-MM-DD.sql
2. Restore File Aplikasi
Masuk ke root directory:
cd /
Extract file backup:
tar -xzvf /root/lychee-files-YYYY-MM-DD.tar.gz
3. Atur Permission
chown -R www-data:www-data /var/www/gallery/Lychee
chmod -R 755 /var/www/gallery/Lychee
4. Restart Web Server
Apache:
systemctl restart apache2
atau
Nginx:
systemctl restart nginx
B. Restore dari Google Drive
1. Download Backup
rclone copy gdrive:backup-lychee/lychee-db-YYYY-MM-DD.sql /root/
rclone copy gdrive:backup-lychee/lychee-files-YYYY-MM-DD.tar.gz /root/
Pastikan file tersedia:
ls -lh /root/
2. Lakukan Restore
Ikuti langkah pada bagian A:
- Restore database
- Extract file
- Set permission
- Restart service
IV. Verifikasi Setelah Restore
Periksa konfigurasi database:
nano /var/www/gallery/Lychee/.env
Pastikan:
DB_DATABASE
DB_USERNAME
DB_PASSWORD
DB_HOST
sesuai dengan database yang digunakan.
Cek juga:
- Website dapat diakses
- Foto tampil normal
- Tidak ada error 500
- Storage memiliki permission yang benar
V. Prinsip Backup yang Benar
Sistem backup yang baik harus memiliki:
- Backup database
- Backup file aplikasi dan foto
- Penyimpanan offsite (Google Drive)
- Otomatisasi terjadwal
- Uji restore berkala
Backup dianggap valid hanya jika berhasil direstore tanpa error.
Dengan sistem ini, server Lychee memiliki:
- Backup harian otomatis
- Salinan lokal dan cloud
- Prosedur restore yang jelas
- Perlindungan terhadap kehilangan data
Jika ingin meningkatkan sistem lebih lanjut, dapat dikembangkan menjadi:
- Backup incremental khusus folder foto
- Enkripsi remote Google Drive
- Monitoring kegagalan backup
- Strategi disaster recovery terstruktur
Dokumentasi ini mencakup seluruh alur dari backup database hingga restore dari rclone secara lengkap dan siap digunakan pada lingkungan produksi.