LINUX.ORG.RU

Бэкап скрипт


0

0

Подкиньте скриптец, который архивирует определенные диры, шифрует...

Кароче всё что связано с бэкапом, можно даже на экзотике типа лиспа.

anonymous

Re: Бэкап скрипт

Сейчас, только шнурки завяжу и подкину

anonymous ()

Re: Бэкап скрипт

а чО тебе на халяву не надо?

anonymous ()

Re: Бэкап скрипт

Легко, только вот без шифрования. Список архивируемых/удаляемых каталогов берётся из backupFsList.dat/backupExcludeList.dat, архивы складываются в $storageDir. Если указать первый аргумент "z" или "j", то архив будет упакован gzip/bzip2(переименовать потом вручную).

#!/bin/sh
###########################################################################
#   Copyright (C) 2006 by Alexander Galanin                               #
#   gaa.nnov@mail.ru                                                      #
#                                                                         #
#   This program is free software; you can redistribute it and/or modify  #
#   it under the terms of the GNU General Public License as published by  #
#   the Free Software Foundation; either version 3 of the License, or     #
#   (at your option) any later version.                                   #
#                                                                         #
#   This program is distributed in the hope that it will be useful,       #
#   but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#   GNU General Public License for more details.                          #
#                                                                         #
#   You should have received a copy of the GNU General Public License     #
#   along with this program; if not, write to the                         #
#   Free Software Foundation, Inc.,                                       #
#   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA               #
###########################################################################

###########################################################################
#                               HISTORY                                   #
###########################################################################
# Date       # Version # Author        # Comment                          #
###########################################################################
# 06.05.2007 #  0.1.0  # A.Galanin     # Creation                         #
# 30.05.2007 #  0.1.1  # A.Galanin     # Added function displayMessage()  #
#            #         #               # Added tar return codes checking  #
#            #         #               # Added Date in history header     #
# 11.02.2008 $  0.1.2  # A.Galanin     # Updated license header           #
###########################################################################

# constat definitions
configRoot=/usr/local/gaa-tools
fsList=${configRoot}/backupFsList.dat
excludeList=${configRoot}/backupExcludeList.dat
storageDir=/home/backup

# global variables
hostname=`uname -n`
backupDate=`date '+%Y%m%d'`
doGzip="$1"

# functions
getTarName () {
	if [ "$1" = "/" ]
	then
		fsName=root
	else
		fsName=`echo $1 | sed 's|^/||' | sed 's|/|_|g'`
	fi
	echo -n ${hostname}-${fsName}-${backupDate}.tar
	[ "$doGzip" = "z" ] && echo -n .gz
}

generateExcludeParam () {
	(
		echo "${storageDir}"
		egrep -v '^#|^$' "${fsList}" | \
			while read s
			do
				echo ${fs} | egrep -q "^${s}" || echo "${s}"
			done
		egrep -v '^#|^$' "${excludeList}"
	) | awk '{print "--exclude=" $0}'
}

exitAndClean () {
	echo "Received signal. Exitting..."
	exit
}

displayMessage () {
	echo -n `date -u` " "
	echo "$@"
}

#------------------------------------------------------
#    MAIN
#------------------------------------------------------

trap exitAndClean 2 9 15

# creating backup storage directory and setting permissions on it
mkdir -p "${storageDir}"
chown 0:0 "${storageDir}"
chmod 700 "${storageDir}"

# processing FS list
cat ${fsList} | egrep -v '^#|^$' | \
while read fs
do
	displayMessage -n Dumping $fs...
	(trap exit 1;while true; do echo -n .;sleep 1;done) &
	patiencePID=$!

	tarName=`getTarName ${fs}`
	excludeParam=`generateExcludeParam "${fs}"`
	echo cf${doGzip} "${storageDir}/${tarName}" "${excludeParam}" "${fs}" | xargs tar
	tarExitCode="$?"
	kill -1 ${patiencePID}

	if [ "$tarExitCode" -eq 0 ]
	then
		displayMessage " SUCCESS."
	else
		displayMessage " FAILED!"
		exit 1
	fi
done

displayMessage "Successfully completed."
exit 0

gaa ★★ ()

Re: Бэкап скрипт

rsnapshot

anonymous ()

Re: Бэкап скрипт

#!/bin/bash
# backup2dvd
DEVICE=${DEVICE:-/dev/dvd}
ISO=${ISO:-$HOME/backup.iso}
DIRS=${DIRS:-"work/=$HOME/work backup/=$HOME/backup SLACK/=$HOME/SLACK"}
#DIRS=${DIRS:-"backup/=$HOME/backup"}

MKISOFS_OPT='-r -T -hide-rr-moved -graft-points -iso-level 3 -no-bak'
VOLUME=$(date +"%Y-%m-%d--%H-%M")

EXCLUDE_FILE="${0}_exclude"

[ -f "$ISO" ] || \
 genisoimage -o "$ISO" -v -exclude-list "$EXCLUDE_FILE"  -V "$VOLUME" $MKISOFS_OPT $DIRS || exit 1

growisofs -dvd-compat -Z $DEVICE="$ISO" || exit 1

exit 0


======================================

#!/bin/bash
# backup2hd
BACKUPDIR=/media/backup
EXCLUDE_FILE="${0}_exclude"
TIME=$(date "+%Y%m%d-%H%M%S")
DATE=$(date "+%Y%m%d")
MAX_FILES=7


REMOVE_OLDEST ()
{
	mask=$1
	MAX_FILES=${2:-14}
	echo -en "REMOVE_OLDEST: ${mask} : "
	files="$(ls -1t "${BACKUPDIR}"/${mask})"
	echo "${files}" | wc -l
	if expr "$(echo "$files" | wc -l)" ">" "$MAX_FILES" &>/dev/null; then
		to_remove=$(echo "$files" | tail -1)
		echo "Removing ${to_remove}"
		rm -f "${to_remove}"
		return 0
	fi
	return 1
}

mount | grep "$BACKUPDIR" || exit 1

cd "$BACKUPDIR" || exit 1

if [ -z "$*" ]; then
	opts="etc home root music dist"
else
	opts="$*"
fi

if echo $opts | grep -oi etc; then
	rsync -a --delete --force /etc/ ./etc/
	REMOVE_OLDEST "etc_tar/etc-*.tar.bz2"
	mkdir -p ./etc_tar || exit 1
	[ -f ./etc_tar/etc-$DATE.tar.bz2 ] || tar cjf ./etc_tar/etc-$DATE.tar.bz2 ./etc
	echo $TIME > ./etc.time
fi

if echo $opts | grep -oi home; then
	rsync --progress -a --delete --force --exclude-from="$EXCLUDE_FILE" /home/ ./home/
	echo $TIME > ./home.time
fi

if echo $opts | grep -oi root; then
	rsync --progress -a --delete --force --exclude-from="$EXCLUDE_FILE" /root/ ./root/
	echo $TIME > ./root.time
fi

if echo $opts | grep -oi music; then
	rsync --progress -a --delete --force /storage/music/ ./music/
	echo $TIME > ./music.time
fi

if echo $opts | grep -oi dist; then
	rsync --progress -a --delete --force /storage/dist/ ./dist/
	echo $TIME > ./dist.time
fi

if echo $opts | grep -oi iso; then
	rsync --progress -a --delete --force /storage/iso/ ./iso/
	echo $TIME > ./iso.time
fi

if echo $opts | grep -oi htdocs; then
	rsync --progress -a --delete --force /var/www/htdocs/ ./htdocs/
	echo $TIME > ./htdocs.time
fi

sync

mount | grep "$BACKUPDIR"


==============================

#!/bin/bash
# backup_dotfiles
BACKUPDIR="$HOME/backup"
HOUR=$(date +"%Y-%m-%d--%H")
DAY=$(date +"%Y-%m-%d")
MONTH=$(date +"%Y-%m")
WEEK=$(date +"%Y-w%U")

REMOVE_OLDEST ()
{
	mask=$1
	MAX_FILES=${2:-14}
	echo -en "REMOVE_OLDEST: ${mask} : "
	files="$(ls -1t "${BACKUPDIR}"/${mask})"
	echo "${files}" | wc -l
	if expr "$(echo "$files" | wc -l)" ">" "$MAX_FILES" &>/dev/null; then
		to_remove=$(echo "$files" | tail -1)
		echo "Removing ${to_remove}"
		rm -f "${to_remove}"
		return 0
	fi
	return 1
}

mkdir -p "$BACKUPDIR" || exit 1
chmod -R u+w "$BACKUPDIR" || exit 1

REMOVE_OLDEST "dotfiles_*.tar.bz2" 7


pushd "$HOME" || exit 1

if ! [ -f "${BACKUPDIR}/dotfiles_${WEEK}.tar.bz2" ]; then
	find -iname .\* -maxdepth 1 | grep -v ^.$ > "$BACKUPDIR"/list || exit 1
	tar cfjv "${BACKUPDIR}/dotfiles_${WEEK}.tar.bz2" -T "$BACKUPDIR"/list -X .backup_exclude || exit 1
fi

popd || exit 1
exit 0


ip1981 ☆☆ ()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.