vhost-stack/bin/vhost-archive.sh

51 lines
1.2 KiB
Bash
Raw Normal View History

2023-04-13 16:17:13 -07:00
#!/bin/bash
#
# vhost-stack
# https://git.stack-source.com/msb/vhost-stack
2023-04-13 16:19:39 -07:00
# Copyright (c) 2023 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>
2023-04-13 16:17:13 -07:00
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# load include file
source $(dirname $0)/vhost.sh
help()
{
thisfilename=$(basename -- "$0")
echo "Create archive of virtualhost on this server. Includes website files, server configs and MySQL databases."
echo ""
echo "usage: $thisfilename -d <domain> [OPTIONS]"
echo ""
echo " -h Print this help."
echo " -d <domain> Domain name of VirtualHost to create archive for."
exit
}
vhost:getoptions "$@"
# check for domain (virtualhost)
if [[ -z $domain ]]; then
echo "domain is required"
exit
fi
if [[ -d /srv/www/$domain ]]; then
username=$(stat -c '%U' /srv/www/$domain)
else
echo "virtualhost for $domain does not exist"
exit 1
fi
2023-09-01 15:33:08 -07:00
# create export of vhost settings
/usr/local/bin/vhost-exp.sh -d $domain
2023-04-13 16:17:13 -07:00
2023-09-01 15:33:08 -07:00
# copy user home dir
cp --archive --parents /home/$username /srv/www/$domain/.exp/
2023-04-13 16:17:13 -07:00
2023-09-01 15:33:08 -07:00
# make sure archive dir exists
2023-04-13 16:17:13 -07:00
if [[ ! -d /opt/archives ]]; then
mkdir /opt/archives
fi
2023-09-01 15:33:08 -07:00
# create tarball
2023-04-13 16:17:13 -07:00
tar --directory=/srv/www/ -czf /opt/archives/$domain.tar.gz $domain