Merge branch 'master' into debian
This commit is contained in:
commit
620dc6c88b
|
@ -41,6 +41,14 @@ apt update
|
|||
apt install bkctld
|
||||
~~~
|
||||
|
||||
### Chroot dependency
|
||||
|
||||
Chroot jail use part of this package
|
||||
|
||||
~~~
|
||||
apt install bash coreutils sed dash mount rsync openssh-server openssh-sftp-server libc6-i386 libc6
|
||||
~~~
|
||||
|
||||
#### Install cron for incremental backup
|
||||
|
||||
Edit root crontab
|
||||
|
|
66
bkctld
66
bkctld
|
@ -58,22 +58,6 @@ check_jail_on() {
|
|||
echo $status
|
||||
}
|
||||
|
||||
check_btrfs() {
|
||||
grep $(dirname $JAILDIR) /etc/fstab|grep -q btrfs
|
||||
if [[ $? -eq 0 ]]; then
|
||||
exit 0
|
||||
fi
|
||||
grep $JAILDIR /etc/fstab|grep -q btrfs
|
||||
if [[ $? -ne 0 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
grep $INCDIR /etc/fstab|grep -q btrfs
|
||||
if [[ $? -ne 0 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
}
|
||||
|
||||
## get functions : get info on jail
|
||||
|
||||
get_port() {
|
||||
|
@ -138,7 +122,7 @@ set_key() {
|
|||
set_ip() {
|
||||
jail=$1
|
||||
ip=$2
|
||||
if [[ $ip = "all" || $ip = "0.0.0.0/0" ]]; then
|
||||
if [ "$ip" = "all" ] || [ "$ip" = "0.0.0.0/0" ]; then
|
||||
ips="0.0.0.0/0"
|
||||
else
|
||||
ips=$(get_ip $jail)
|
||||
|
@ -227,8 +211,10 @@ sub_init() {
|
|||
exit 1
|
||||
fi
|
||||
|
||||
echo "Create jail $jail :"
|
||||
if ( check_btrfs); then
|
||||
echo "Create jail $jail :"
|
||||
rootdir_inode=$(stat --format=%i $(dirname $JAILDIR))
|
||||
jaildir_inode=$(stat --format=%i $JAILDIR)
|
||||
if [ "$rootdir_inode" -eq 256 ] || [ "$jaildir_inode" -eq 256 ]; then
|
||||
/sbin/btrfs subvolume create ${JAILDIR}/${jail}
|
||||
else
|
||||
mkdir -p ${JAILDIR}/${jail}
|
||||
|
@ -274,17 +260,23 @@ sub_remove() {
|
|||
log stop $jail
|
||||
fi
|
||||
echo "Delete jail $jail ..."
|
||||
if ( check_btrfs ); then
|
||||
rm -f ${CONFDIR}/${jail}
|
||||
if [ -d ${INCDIR}/${jail} ]; then
|
||||
/sbin/btrfs subvolume delete ${INCDIR}/${jail}/*
|
||||
rmdir ${INCDIR}/${jail}
|
||||
fi
|
||||
rm -f ${CONFDIR}/${jail}
|
||||
jail_inode=$(stat --format=%i ${JAILDIR}/${jail})
|
||||
if [ "$jail_inode" -eq 256 ]; then
|
||||
/sbin/btrfs subvolume delete ${JAILDIR}/${jail}
|
||||
else
|
||||
rm -f ${CONFDIR}/${jail}
|
||||
rm -rf ${JAILDIR}/${jail}
|
||||
echo "You need to purge ${INCDIR}/${jail} manually !"
|
||||
fi
|
||||
if [ -d ${INCDIR}/${jail} ]; then
|
||||
for inc in $(ls ${INCDIR}/${jail}); do
|
||||
inc_inode=$(stat --format=%i ${INCDIR}/${jail}/$inc)
|
||||
if [ "$inc_inode" -eq 256 ]; then
|
||||
/sbin/btrfs subvolume delete ${INCDIR}/${jail}/${inc}
|
||||
else
|
||||
echo "You need to purge ${INCDIR}/${jail}/$inc manually !" >&2
|
||||
fi
|
||||
done
|
||||
rmdir --ignore-fail-on-non-empty ${INCDIR}/${jail}
|
||||
fi
|
||||
set_firewall $jail
|
||||
echo "...OK"
|
||||
|
@ -430,8 +422,9 @@ sub_inc() {
|
|||
mkdir -p ${INCDIR}/${jail}
|
||||
if [ ! -d "${inc}" ]; then
|
||||
start=$(date +"%H:%M:%S")
|
||||
if ( check_btrfs ); then
|
||||
/sbin/btrfs subvolume snapshot ${JAILDIR}/$jail $inc > /dev/null
|
||||
jail_inode=$(stat --format=%i ${JAILDIR}/${jail})
|
||||
if [ "$jail_inode" -eq 256 ]; then
|
||||
/sbin/btrfs subvolume snapshot -r ${JAILDIR}/${jail} $inc > /dev/null
|
||||
else
|
||||
cp -alx ${JAILDIR}/${jail}/ $inc
|
||||
fi
|
||||
|
@ -484,8 +477,9 @@ sub_rm() {
|
|||
#for j in $( ls ${INCDIR}/$jail ); do
|
||||
for j in $( grep -v -f <(echo "${keep}") <(echo "${incs}") ); do
|
||||
start=$(date +"%H:%M:%S")
|
||||
if ( check_btrfs ); then
|
||||
/sbin/btrfs subvolume delete ${INCDIR}/$jail/$j >/dev/null
|
||||
inc_inode=$(stat --format=%i ${INCDIR}/${jail}/${j})
|
||||
if [ "$inc_inode" -eq 256 ]; then
|
||||
/sbin/btrfs subvolume delete ${INCDIR}/${jail}/${j} >/dev/null
|
||||
else
|
||||
cd ${INCDIR}/$jail
|
||||
rsync -a --delete $empty $j*
|
||||
|
@ -551,22 +545,22 @@ main() {
|
|||
log $subcommand
|
||||
;;
|
||||
"init")
|
||||
if [[ -n "${jail}" ]]; then
|
||||
if [ -n "${jail}" ]; then
|
||||
log $subcommand $jail
|
||||
else
|
||||
usage
|
||||
fi
|
||||
;;
|
||||
"key" | "port" | "ip")
|
||||
if [[ -n "${jail}" ]]; then
|
||||
if [ -n "${jail}" ]; then
|
||||
log params $jail $subcommand $option
|
||||
else
|
||||
usage
|
||||
fi
|
||||
;;
|
||||
"start" | "stop" | "reload" | "restart" | "sync" | "update" | "remove")
|
||||
if [[ -n "${jail}" ]]; then
|
||||
if [[ "${jail}" = "all" ]]; then
|
||||
if [ -n "${jail}" ]; then
|
||||
if [ "${jail}" = "all" ]; then
|
||||
for jail in $(ls $JAILDIR); do
|
||||
case $subcommand in
|
||||
"start")
|
||||
|
@ -605,7 +599,7 @@ main() {
|
|||
fi
|
||||
;;
|
||||
"status")
|
||||
if [[ -z "${jail}" ]]; then
|
||||
if [ -z "${jail}" ]; then
|
||||
for jail in $(ls $JAILDIR); do
|
||||
sub_$subcommand $jail
|
||||
done
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
.\" Manpage for bkctld.
|
||||
.\" Contact vlaborie@evolix.fr to correct errors or typos.
|
||||
.TH man 8 "24 Mars 2017" "1.2.3" "bkctld man page"
|
||||
.TH man 8 "24 Mars 2017" "1.3" "bkctld man page"
|
||||
.SH NAME
|
||||
bkctld - tool to manage evobackup jail
|
||||
.SH SYNOPSIS
|
||||
|
|
|
@ -33,7 +33,7 @@ trap "rm -f $PIDFILE" EXIT
|
|||
SSH_PORT=2XXX
|
||||
|
||||
# choose "linux" or "bsd"
|
||||
SYSTEME=$(uname | tr '[:upper:]' '[:lower:]')
|
||||
SYSTEM=$(uname | tr '[:upper:]' '[:lower:]')
|
||||
|
||||
# email adress for notifications
|
||||
MAIL=jdoe@example.com
|
||||
|
@ -97,6 +97,10 @@ mkdir -p -m 700 /home/backup
|
|||
## example with pg_dumpall (warning: you need space in ~postgres)
|
||||
# su - postgres -c "pg_dumpall > ~/pg.dump.bak"
|
||||
# mv ~postgres/pg.dump.bak /home/backup/
|
||||
## another method with gzip directly piped
|
||||
# cd /var/lib/postgresql
|
||||
# sudo -u postgres pg_dumpall | gzip > /home/backup/pg.dump.bak.gz
|
||||
# cd -
|
||||
|
||||
## example with all tables from MYBASE excepts TABLE1 and TABLE2
|
||||
# pg_dump -p 5432 -h 127.0.0.1 -U USER --clean -F t --inserts -f /home/backup/pg-backup.tar -t 'TABLE1' -t 'TABLE2' MYBASE
|
||||
|
@ -159,12 +163,13 @@ done
|
|||
## Dump process with ps
|
||||
ps aux >/home/backup/ps.out
|
||||
|
||||
if [ $SYSTEME = "linux" ]; then
|
||||
if [ $SYSTEM = "linux" ]; then
|
||||
## Dump network connections with netstat
|
||||
netstat -taupen >/home/backup/netstat.out
|
||||
|
||||
## List Debian packages
|
||||
dpkg -l >/home/backup/packages
|
||||
dpkg --get-selections >/home/backup/packages.getselections
|
||||
else
|
||||
## Dump network connections with netstat
|
||||
netstat -finet -atn >/home/backup/netstat.out
|
||||
|
@ -177,9 +182,9 @@ HOSTNAME=$(hostname)
|
|||
|
||||
DATE=$(/bin/date +"%d-%m-%Y")
|
||||
|
||||
DEBUT=$(/bin/date +"%d-%m-%Y ; %H:%M")
|
||||
BEGINNING=$(/bin/date +"%d-%m-%Y ; %H:%M")
|
||||
|
||||
if [ $SYSTEME = "linux" ]; then
|
||||
if [ $SYSTEM = "linux" ]; then
|
||||
rep="/bin /boot /lib /opt /sbin /usr"
|
||||
else
|
||||
rep="/bsd /bin /boot /sbin /usr"
|
||||
|
@ -224,12 +229,12 @@ rsync -avzh --stats --delete --delete-excluded --force --ignore-errors --partial
|
|||
root@$SRV:/var/backup/ \
|
||||
| tail -30 >> /var/log/evobackup.log
|
||||
|
||||
FIN=$(/bin/date +"%d-%m-%Y ; %H:%M")
|
||||
END=$(/bin/date +"%d-%m-%Y ; %H:%M")
|
||||
|
||||
echo "EvoBackup - $HOSTNAME - START $DEBUT" \
|
||||
echo "EvoBackup - $HOSTNAME - START $BEGINNING" \
|
||||
>> /var/log/evobackup.log
|
||||
|
||||
echo "EvoBackup - $HOSTNAME - STOP $FIN" \
|
||||
echo "EvoBackup - $HOSTNAME - STOP $END" \
|
||||
>> /var/log/evobackup.log
|
||||
|
||||
tail -10 /var/log/evobackup.log | \
|
||||
|
|
Loading…
Reference in a new issue