37 lines
509 B
Bash
37 lines
509 B
Bash
#! /bin/bash
|
|
|
|
set -eu
|
|
|
|
if [ "$#" -ne 1 ] ; then
|
|
echo "Usage: $O dir_to_backup"
|
|
exit 1
|
|
fi
|
|
|
|
test -d "$1" || {
|
|
echo "$1 don't exist or not a dir"
|
|
exit 2
|
|
}
|
|
|
|
if [ ! -d "$1" ] ; then
|
|
echo "$1 don't exist or not a dir"
|
|
exit 2
|
|
fi
|
|
|
|
src=$1
|
|
dest=/var/backups/$(date -I)
|
|
|
|
mkdir -p "${dest}" || exit 3
|
|
|
|
# tar cpzf /var/backups/$(date -I)/etc.tgz /etc
|
|
tar cpzf "${dest}/${src}.tgz" "${src}"
|
|
ret=$?
|
|
|
|
if [ $ret -eq 0 ] ; then
|
|
find "${dest}" -maxdepth 1 -type f -mtime +7 -exec echo rm {} \;
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
exit $ret |