Samba-ad-dc-with-docker/packages/restore.sh

92 lines
1.6 KiB
Bash
Raw Normal View History

2022-10-08 15:47:42 +09:00
#!/bin/bash
WORKDIR=${PWD}
# Check parameters.
if [ $# = 0 ]; then
echo "Usage: restore.sh [path to backup file] [--execute]
--execute Execute a restore.
If this parameter is not present, a dry run is performed."
exit 0
fi
if [ ! -e $1 ]; then
echo "File to be restored not found: $1"
exit -1
fi
# Extract file.
if [ -d ./restore ]; then
echo "The directory \"restore\" exists. Aborted."
exit 0
fi
mkdir ./restore
tar -zxvf $1 -C ./restore
if [ $? -ne 0 ]; then
echo "Failed to extract file."
exit -1
fi
#
if [ -z $2 ]; then
# Restore acl.
cd restore/lib/samba/
bash ./NTACL
echo "Finished dry run."
elif [ $2 = "--execute" ]; then
# Stop the samba process.
pkill -SIGTERM ^samba$
while
pgrep ^samba$
[ $? -eq 0 ]
do
echo "wait..."
sleep 1
done
# Samba
# Restore files.
rm -rf /etc/samba/*
mv restore/etc/samba/* /etc/samba/
rm -rf /var/lib/samba/private/*
mv restore/lib/samba/private/* /var/lib/samba/private/
rm -rf /var/lib/samba/bind-dns
mv restore/lib/samba/bind-dns /var/lib/samba/
rm -rf /var/lib/samba/sysvol/*
mv restore/lib/samba/sysvol/* /var/lib/samba/sysvol/
# Bind
# Restore files.
rm -rf /etc/bind/*
mv restore/etc/bind/* /etc/bind/
rm -rf /var/lib/bind/*
mv restore/lib/bind/* /var/lib/bind/
# Delete working files.
rm -rf ./restore
# Restore acl.
cd /var/lib/samba
bash $WORKDIR/restore/lib/samba/NTACL
cd $WORKDIR
# Do sysvol reset.
net cache flush
samba-tool ntacl sysvolreset
# Start the samba process.
/usr/sbin/samba --interactive --no-process-group &
if [ $SMB_USEBIND9 = "true" ]; then
/usr/sbin/rndc stop
/usr/sbin/named -u bind
fi
echo "Restored."
fi