Created
May 18, 2020 20:23
-
-
Save DreamVB/15d7bb309870052ce3a0aa9e6ba8810f to your computer and use it in GitHub Desktop.
A simple Bash Script I made To Backup My Files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| SRCDIR="files" | |
| #Set to 1 to delete backup files older than 30 days. otherwise set to zero | |
| RemoveOldBackups=1 | |
| #Set a filename based on date and time. | |
| FILENAME=$(date +"%FT%H%M%S").tgz | |
| #Make backup folder | |
| mkdir -p "Backups" | |
| #This is the backed up filename. | |
| BACKUP_FILE="Backups/$FILENAME" | |
| #Display message | |
| echo "Running Backup." | |
| #Compress the $SRCDIR | |
| tar -cvf $BACKUP_FILE $SRCDIR | |
| #Get size of backup file. | |
| BACKUP_SIZE=$(stat -c%s $BACKUP_FILE) | |
| #Delete files more than 30 days old | |
| if [ $RemoveOldBackups = 1 ]; then | |
| find ./Backups -type f -mtime +30 -exec rm -f {} \; | |
| fi | |
| #Display status | |
| echo "" | |
| echo "Backup File Created : $BACKUP_FILE" | |
| echo "Backup File Size : $BACKUP_SIZE bytes(s)" | |
| echo "Finished backup." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment