From: root Date: Sat, 4 Oct 2014 20:14:48 +0000 (+0200) Subject: Add files that were never in RCS. X-Git-Url: https://git.sesse.net/?p=backup.sh;a=commitdiff_plain;h=23355d3ce4452e989e5816d077bbc6a80a1bf2d2 Add files that were never in RCS. --- diff --git a/clean-pitr.sh b/clean-pitr.sh new file mode 100755 index 0000000..ea5c666 --- /dev/null +++ b/clean-pitr.sh @@ -0,0 +1,10 @@ +#! /bin/sh + +# PITR-filer er ubrukelige uten en fullbackup å basere seg på. +# Finn eldste fullbackup og slett alt som er eldre enn det. +# -sesse/itk, feb 2010 + +OLDEST_FULLBACKUP=$( ls -1t /backup/cirkus/_var_lib_postgresql/full/*.tgz | tail -n 1 ) +if [ -r "$OLDEST_FULLBACKUP" ]; then + find /home/pgbackup/pgbackup-cirkus/ -not -newer $OLDEST_FULLBACKUP -exec rm '{}' + +fi diff --git a/list-incr.sh b/list-incr.sh new file mode 100755 index 0000000..8bf99bf --- /dev/null +++ b/list-incr.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +DIR=$1 +LASTFULL=$(ls $DIR/full | tail -n1) +if [ ! -f "$DIR/full/$LASTFULL" ]; then + echo "No full backup found" + echo "Usage example: $0 /backup/cirkus/_var_lib_postgresql" + exit 1 +fi +# Get timestamp on form 2012-10-15 00:16 +LASTFULL_TIMESTAMP=$(echo `basename $LASTFULL .tgz` | sed -re 's/^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2}).*/\1-\2-\3 \4:\5/') +find $DIR/full/$LASTFULL +find $DIR/daglig -newermt "$LASTFULL_TIMESTAMP" -name '*.tgz' diff --git a/skruebackup.sh b/skruebackup.sh new file mode 100755 index 0000000..b7a4445 --- /dev/null +++ b/skruebackup.sh @@ -0,0 +1,123 @@ +#! /bin/bash + +### About +# Written by Stein Magnus Jodal +# Distributed under the GNU General Public License version 2. + +### ChangeLog +# 2003-10-20 Stein Magnus Jodal +# - Started, but I was too tired and went home. +# +# 2003-10-22 Stein Magnus Jodal +# - Continued, but I started to chat instead. +# +# 2003-10-27 Stein Magnus Jodal +# - The script started looking like something usefull. +# +# 2003-11-10 Stein Magnus Jodal +# - The script can now delete old archives! +# +# 2004-10-17 Stein Magnus Jodal +# - The script now creates the storagedirs if they don't exists. +# - The delete old archives part doesn't fail if we don't have any old archives +# anymore. (shopt -s nullglob, so the script now requires bash) +# - Fixed s/:/;/ at one of the lines. This made the first backup run use +# "full:" instead of "full" as target dir. +# +# 2004-10-18 Stein Magnus Jodal +# - Fixed the calculation of $LIMIT and added a new check under the deletion +# part + +### Usage +# skruebackup.sh -full +# Run full backup +# +# skruebackup.sh -incr +# Run incremental backup (default if the lastrun file exists) +# +# Example for crontab usage: +# 0 4 1 * * /path/to/skruebackup.sh -full +# 0 6 * * * /path/to/skruebackup.sh -incr + +### Vars +# Number of archives to keep +NUMFULL=3 # months (31 days) +NUMINCR=40 # days +# Dir to store the backups to +STORAGEDIR="/backup/skrue"; +# File listing what dirs to backup +BACKUPLIST="/home/backup/skruebackup_this.txt"; +# File touched for every backup +LASTRUNFILE="${STORAGEDIR}/skruebackup_lastrun"; +# Programs +SMBTAR="/usr/bin/smbtar -s skrue -x tilkolje -u skruebackup -p 'gl25bE!v' -t -"; +GZIP="/bin/gzip -6"; +# Dates +TODAY=$(date +%Y-%m-%d); +TODAY_EPOCH=$(date +%s); + +### DON'T EDIT ANYTHING BELOW THIS LINE ### + +# If we got empty dirs, we don't want dir/* to be passed on +shopt -s nullglob + +### Create dirs +if [ ! -d ${STORAGEDIR} ]; then + echo "--- Creating backup dir"; + mkdir -vp ${STORAGEDIR}/full ${STORAGEDIR}/incr; +fi + +### Delete old archives +echo "--- Deleting old archives"; + +# Deleting old full archives +LIMIT=$(( ${TODAY_EPOCH} - ${NUMFULL} * 31 * 24 * 60 * 60 )); + +for FILE in ${STORAGEDIR}/full/*; do + if [ -e ${FILE} ]; then + THIS_DATE=$(echo ${FILE} | sed 's/^.*_//; s/\.tar\.gz$//'); + THIS_EPOCH=$(date --date="${THIS_DATE}" +%s); + if [ "${THIS_EPOCH}" -lt "${LIMIT}" ]; then + rm -v ${FILE}; + fi + fi +done + +# Delete old incremental archives +LIMIT=$(( ${TODAY_EPOCH} - ${NUMINCR} * 24 * 60 * 60 )); + +for FILE in ${STORAGEDIR}/incr/*; do + if [ -e ${FILE} ]; then + THIS_DATE=$(echo ${FILE} | sed 's/^.*_//; s/\.tar\.gz$//'); + THIS_EPOCH=$(date --date="${THIS_DATE}" +%s); + if [ "${THIS_EPOCH}" -lt "${LIMIT}" ]; then + rm -v ${FILE}; + fi + fi +done + +### Full or incremental backup +if [ "$1" = "-full" ]; then + echo "--- Running full backup"; + STORAGEDIR="${STORAGEDIR}/full"; +else + if [ -w ${STORAGEDIR}/skruebackup_lastrun ]; then + echo "--- Running incremental backup"; + STORAGEDIR="${STORAGEDIR}/incr"; + SMBTAR="${SMBTAR} -N ${LASTRUNFILE} -i"; + else + echo "--- Running full backup"; + STORAGEDIR="${STORAGEDIR}/full"; + fi +fi + +# The actual backup +for DIR in $(cat ${BACKUPLIST}); do + echo ">>> Currently processing ${DIR}"; + ${SMBTAR} -d ${DIR} | ${GZIP} > ${STORAGEDIR}/skruebackup_${DIR}_${TODAY}.tar.gz; +done + +### Updating last runned record +echo "--- Updating last runned record"; +touch ${LASTRUNFILE}; +