Skip to content

Instantly share code, notes, and snippets.

@sorinmircea
Created October 16, 2025 19:50
Show Gist options
  • Save sorinmircea/eb760771d74eb04e7f5606c498499af8 to your computer and use it in GitHub Desktop.
Save sorinmircea/eb760771d74eb04e7f5606c498499af8 to your computer and use it in GitHub Desktop.
Backup script for my VPS
#!/bin/sh
BACKUP_DIR=/server/data # Directory to backup
BACKUP_DEST=/server/backups # Backup destination directory
BACKUP_NAME=backup-$(date +%Y%m%d).tar.gz # Name of the backup file with date and compression
LOGFILE=${BACKUP_DEST}/backup-script-$(date '+%Y%m%d').log # Logfile location in same directory but different extension
echo "---------------------------------" >> $LOGFILE
echo "Backup started on $(date)" | tee -a $LOGFILE
/bin/tar -czvf ${BACKUP_DEST}/${BACKUP_NAME} --absolute-names ${BACKUP_DIR} | tee -a $LOGFILE 2>&1
TAR_STATUS=$?
if [ $TAR_STATUS -eq 0 ]; then
echo "Backup finished successfully" | tee -a $LOGFILE
else
echo "Backup failed with status $TAR_STATUS" | tee -a $LOGFILE
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment