Skip to content

Instantly share code, notes, and snippets.

@leemason
Created April 22, 2016 19:48
Show Gist options
  • Save leemason/b55f8751af9c4f466f407ec9babe9cb5 to your computer and use it in GitHub Desktop.
Save leemason/b55f8751af9c4f466f407ec9babe9cb5 to your computer and use it in GitHub Desktop.
Simple tar archive backup script to be placed in the /etc/cron.daily directory.
#!/bin/bash
PATH=/usr/sbin:/usr/bin:/sbin:/bin
stamp=`date +"%s-%A_%d_%B_%Y@%H_%M"`
name="${stamp}_backup.tgz";
#tar filesystem
tar cvpzf /backups/file/${name} --exclude=/backups/file --exclude=/lost+found --exclude=/proc/* --exclude=/sys/* --exclude=/mnt/* --exclude=/media/* --exclude=/tmp/* --exclude=/var/run/* --exclude=/var/lock/* --exclude=/var/cache/apt/archives/* --exclude=/home/*/.gvfs --exclude=/run --exclude=/dev /
#delete files older than 7 days
find /backups/file -type f -mtime +7 -exec rm {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment