This is a bash script to backup directories in tar.bzip2 format giving a meaningful name to the archive.
It takes two parameters: <path> and (optionally) <name>.
<path> is the directory that will be compressed to an archive which will named <name>_<date>.tbz2.
If <name> isn't specified, <path> will be passed throught sed "s:/$::" to remove trailing slash and used as archive name.
Of course, <name> can be a path (ex. if <name> is /path/to/file, the full path of archive will be /path/to/file_<date>.tbz2).
<date> is the result of
date +"%Y%m%d-%H%M%S"
#!/bin/bash # # archive.sh # # ~redShadow~ - http://hackzine.org # redshadow at hackzine dot org # Under GPL # OK="\033[0m[\033[1;32m OK \033[0m]" FAILED="\033[0m[\033[1;31mFAILED\033[0m]" if [ "$1" == "--help" ]; then echo "Usage: $0 <path> [<name>]" exit 0 fi DIRPATH="$1" if [ "$DIRPATH" == "" ]; then echo "You must specify a valid path!" exit 1 fi DATE1="$( /bin/date +"%Y/%m/%d %H:%M:%S" )" DATE="$( /bin/date +"%Y%m%d-%H%M%S" )" if [ "$2" != "" ]; then NAME="$2" else NAME="$(echo "$1" | sed 's:/$::')" fi OUTNAME="${NAME}_${DATE}.tbz2" LOGFILE="/tmp/archive_${DATE}.log" echo "----------------------------------------------------------------" echo -e " \033[1;33m..The Archiver..\033[0m" echo "----------------------------------------------------------------" echo -e "\033[1;37m Directory:\033[0m $DIRPATH" echo -e "\033[1;37m Date:\033[0m $DATE1" echo -e "\033[1;37m Archive name:\033[0m $OUTNAME" echo -e "\033[1;37m LogFile:\033[0m $LOGFILE" echo "----------------------------------------------------------------" echo -n " Creating Archive... " tar cjvf "$OUTNAME" "$DIRPATH" &>$LOGFILE && echo -e "$OK" || echo -e "$FAILED" #cat $LOGFILE # rm $LOGFILE echo "----------------------------------------------------------------"
~redShadow~ <redshadow at hackzine dot org>
Under GPL