Skip to content

Instantly share code, notes, and snippets.

@bartekkois
Created October 16, 2016 08:34
Show Gist options
  • Save bartekkois/a73dc2ad5c5b717e5af38861134f339a to your computer and use it in GitHub Desktop.
Save bartekkois/a73dc2ad5c5b717e5af38861134f339a to your computer and use it in GitHub Desktop.
Script for periodical backup of /etc directory
#!/bin/sh
# ------------ BACKUP 1.0.0 "rc.backup" -------------
# All rights reserved for B@roo 2000-2016
# -----------------------------------------------------
#set -x
# ------------------- Configuration -------------------
DIR=/var/log/backup
# ------------------- Create backup -------------------
FILE=backup-`date '+%Y-%m-%d'`.tar.gz
if [ -e $DIR'/'$FILE ] ; then
echo "Backup already exists !!!"
exit 0
fi
tar cvf - /etc | gzip -c > $DIR'/'$FILE
echo "Backup created."
# --------------- Remove old archives -----------------
find /var/log/backup -ctime +7 -type f -name "backup-*" -exec rm -rf {} \;
echo "Backup rotated."
# Create backup
00 1 * * * root /root/system_scripts/backup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment