#!/bin/bash
today=$(date +%Y%m%d)
basedir=/root/backup/
log=/root/backup/$today.log

echo "Starting backup..." | tee -a $log
echo "Zip $basedir/forgejo/$today.zip..." | tee -a $log
zip -r $basedir/forgejo/$today.zip /opt/forgejo/ > /dev/null
zip -r $basedir/linkding/$today.zip /opt/linkding/ > /dev/null
rm -rf $basedir/nginx/*.conf && cp -r /etc/nginx/conf.d/* $basedir/nginx > /dev/null

echo "Deleting old backups..." | tee -a $log
find /root/backup -name "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].zip" -mtime +6 -ls | tee -a $log
find /root/backup -name "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].zip" -mtime +6 -delete

echo "Syncing to google drive..." | tee -a $log
#rclone sync /root/backup gd:Backups/server
rclone sync /root/backup od:Backups/server
