Skip to content

Instantly share code, notes, and snippets.

@kainjinez
Created February 8, 2021 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kainjinez/c50d19ffeba4164b4861edd4bed8d81b to your computer and use it in GitHub Desktop.
Save kainjinez/c50d19ffeba4164b4861edd4bed8d81b to your computer and use it in GitHub Desktop.
# PUS EDU Plugin - Backup Server and Upload to Cloud
# Version: 2.0
#!/bin/bash
SERVER_NAME=$(hostname)
TIMESTAMP=$(date +"%F")
BACKUP_DIR="/home/backup/$TIMESTAMP"
SECONDS=0
size=$(du -sh $BACKUP_DIR | awk '{ print $1}')
echo "Bat Dau Backup thu muc $BACKUP_DIR";
/usr/sbin/rclone move $BACKUP_DIR "remote:$SERVER_NAME/$TIMESTAMP" >> /var/log/rclone.log 2>&1
# Clean up
rm -rf $BACKUP_DIR
/usr/sbin/rclone -q --min-age 6w delete "remote:$SERVER_NAME" #Remove all backups older than 2 week
/usr/sbin/rclone -q --min-age 6w rmdirs "remote:$SERVER_NAME" #Remove all empty folders older than 2 week
/usr/sbin/rclone cleanup "remote:" #Cleanup Trash
echo "Finished";
echo '';
duration=$SECONDS
echo "Total $size, $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment