Nützliches Script für den "Hausgebrauch"
Beispiel: sicherung.sh full --without home (Sichert das komplette System bis auf die Home-Verzeichnisse)
- #!/bin/sh
- ################################################################################
- #
- # Backup Script
- # Author: Manuel Strauch
- #
- ################################################################################
- ### Zu sichernde Verzeichnisse + Dateien
- system="bin boot dev etc lib libexec proc sbin sys tmp usr var"
- rescue="rescue"
- optional="opt"
- mountpoints="media mnt"
- files="COPYRIGHT"
- compat=" "
- homes="home root"
- webpage="usr/local/etc/apache22 usr/local/www"
- jails="etc/rc.conf usr/jails"
- ## Dateien oder Verzeichnisse nicht sichern!
- ## Backup-Verzeichnis wird automatisch nicht gesichert.
- exclude="usr/ports/distfiles"
- ## Backup Verzeichnis
- tar_dir="/usr/Sicherung"
- ### Tar Optionen usw.
- version="1.2"
- zip="bzip2"
- # zip="gzip"
- compress="-v9"
- ## =================== Don`t TOUCH ===================
- . /opt/etc/system.var
- backup_date="`date +%Y-%m-%d`"
- check_without="no"
- tar_options="-cvp"
- system_name="`uname | tr [A-Z] [a-z]`"
- system_release="`uname -r | tr [A-Z] [a-z]`"
- system_hostname="`hostname | cut -f1 -d.`"
- tar_file_string="${system_hostname}-${1}-${system_name}-${system_release}-${backup_date}"
- backup_file="${tar_dir}/backup-${tar_file_string}.tar"
- log_file="${tar_dir}/backup-${tar_file_string}.log"
- exclude="`echo ${tar_dir} | sed 's/^\///g'` ${exclude}"
- ### Funktionen
- search_options() {
- testing="${2}"
- if [ ! -z "$testing" ]; then
- case "${2}" in
- --without|--backup)
- shift
- for i in ${@}; do
- case "${i}" in
- --without)
- check_without="yes"
- ;;
- --backup)
- check_without="no"
- ;;
- *)
- if [ "${check_without}" = "yes" ]; then
- exclude="${exclude} ${i}"
- else
- tar_backup="${tar_backup} ${i}"
- fi
- ;;
- esac
- done
- ;;
- *)
- echo "syntax error!!"
- echo "option { "${@}" } was not supported!"
- exit 1
- ;;
- esac
- fi
- }
- start_backup() {
- cd /
- if [ "${zip}" = "bzip2" ]; then
- backup_file="${backup_file}.bz2"
- else
- if [ "$zip" = "gzip" ]; then
- backup_file="${backup_file}.gz"
- else
- echo " "
- echo "unsupported compress method!"
- echo "use bzip2 or gzip"
- exit 1
- fi
- fi
- for i in ${exclude}; do
- excludeline="${excludeline} --exclude=${i}"
- done
- echo "You can see the files in the logfile: "
- echo "${log_file}"
- echo -e " --> Backup: >>starting `date `<< ${ISRUNNING}"
- (
- tar ${tar_options} ${excludeline} -f - ${tar_backup} | \
- ${zip} ${compress} > "${backup_file}"
- ) > "${log_file}" 2>&1
- echo -e " --> Backup: >>finished `date`<< ${ISTERMINATED}"
- }
- ### Programm
- case "${1}" in
- full)
- tar_backup="${system} ${rescue} ${optional} ${mountpoints} ${files} ${compat} ${homes}"
- search_options "${@}"
- start_backup
- ;;
- www)
- tar_backup="${webpage}"
- search_options "${@}"
- start_backup
- ;;
- homes)
- tar_backup="${homes}"
- search_options "${@}"
- start_backup
- ;;
- jails)
- tar_backup="${jails}"
- search_options "${@}"
- start_backup
- ;;
- manuell)
- search_options "${@}"
- start_backup
- ;;
- help)
- cat <<__USAGE__
- hoschis backup script version ${version}
- ==================================
- usage: ${0} { full | www | homes | jails | manuell | help }
- ----------------------------------
- special options:
- --without
- ----------------------------------
- manuell syntax:
- ${0} manuell --backup bin boot --without home
- or
- ${0} manuell --without bin boot --backup home
- ----------------------------------
- syntax:
- ${0} full --without home
- ----------------------------------
- __USAGE__
- ;;
- *)
- echo "usage: ${0} help"
- echo "for help"
- ;;
- esac
- exit 0