Bug fixes / Git ignore for parsed backup.cfg
This commit is contained in:
parent
c4cf0729b6
commit
8f72e7ff98
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
sbackup.cfg
|
@ -1,30 +1,23 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# --------------------------------------------------------
|
# --------------------------------------------------------
|
||||||
# Please double check Your settings
|
# Please double check Your settings
|
||||||
# --------------------------------------------------------
|
# --------------------------------------------------------
|
||||||
|
|
||||||
enabled=false #enable main function
|
enabled=false #enable main function
|
||||||
|
|
||||||
www_backup=false # backup wwwroot
|
www_backup=false # backup wwwroot
|
||||||
www_dir='xyz' # wwwroot location
|
www_dir='xyz' # wwwroot location
|
||||||
|
|
||||||
vhost_backup=false # backup vhost config
|
vhost_backup=false # backup vhost config
|
||||||
vhost_dir='/etc/httpd/sites-enabled' # vhost location
|
vhost_dir='/etc/httpd/sites-enabled' # vhost location
|
||||||
|
|
||||||
log_backup=false # backup logs
|
log_backup=false # backup logs
|
||||||
log_backup_web=false # backup webapp logs
|
log_backup_web=false # backup webapp logs
|
||||||
apache=false # apache log backup
|
apache=false # apache log backup
|
||||||
nginx=false # nginx log backup
|
nginx=false # nginx log backup
|
||||||
fail2ban_log=false # fail2ban log backup
|
fail2ban_log=false # fail2ban log backup
|
||||||
log_purge=false # purge logs after backup
|
log_purge=false # purge logs after backup
|
||||||
|
|
||||||
rsync_push=false # enable push to remote server
|
rsync_push=false # enable push to remote server
|
||||||
push_clean=false # clean backup file after push
|
push_clean=false # clean backup file after push
|
||||||
target_host="127.0.0.1" # rsync target host
|
target_host="127.0.0.1" # rsync target host
|
||||||
target_user="backup" # rsync target user
|
target_user="backup" # rsync target user
|
||||||
target_key='/home/xyz/.ssh/rsync' # rsync key
|
target_key='/home/xyz/.ssh/rsync' # rsync key
|
||||||
|
|
||||||
docker_enabled=false # will you use docker backup
|
docker_enabled=false # will you use docker backup
|
||||||
docker_images=false # backup docker images
|
docker_images=false # backup docker images
|
||||||
docker_volumes=false #backup docker volumes
|
docker_volumes=false #backup docker volumes
|
||||||
|
61
main.sh
61
main.sh
@ -5,16 +5,17 @@ echo "Backify is starting, looking for configuration file..." >&2
|
|||||||
config='backup.cfg'
|
config='backup.cfg'
|
||||||
config_secured='sbackup.cfg'
|
config_secured='sbackup.cfg'
|
||||||
|
|
||||||
if config -f "$config"; then
|
if [ -f "$config" ]
|
||||||
|
then
|
||||||
echo "Configuration found." >&2
|
echo "Configuration found." >&2
|
||||||
else
|
else
|
||||||
echo "Configuration not found" >&2
|
echo "Configuration not found" >&2
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if egrep -q -v '^#|^[^ ]*=[^;]*' "$config"; then
|
if grep -E -q -v '^#|^[^ ]*=[^;]*' "$config"; then
|
||||||
echo "Config file is unclean, cleaning it..." >&2
|
echo "Config file is unclean, cleaning it..." >&2
|
||||||
egrep '^#|^[^ ]*=[^;&]*' "$config" > "$config_secured"
|
grep -E '^#|^[^ ]*=[^;&]*' "$config" > "$config_secured"
|
||||||
config="$config_secured"
|
config="$config_secured"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -34,7 +35,8 @@ tmpdir="/tmp/backify-$timestamp"
|
|||||||
}
|
}
|
||||||
|
|
||||||
function wwwbackup {
|
function wwwbackup {
|
||||||
if [ "$www_backup" = true ] then
|
if [ "$www_backup" = true ]
|
||||||
|
then
|
||||||
echo "Backing up wwwroot..." >&2
|
echo "Backing up wwwroot..." >&2
|
||||||
mkdir -p $tmpdir/wwwdata
|
mkdir -p $tmpdir/wwwdata
|
||||||
cp -r $www_dir/ $tmpdir/wwwdata/
|
cp -r $www_dir/ $tmpdir/wwwdata/
|
||||||
@ -43,7 +45,8 @@ fi
|
|||||||
}
|
}
|
||||||
|
|
||||||
function vhostbackup {
|
function vhostbackup {
|
||||||
if [ "$vhost_backup" = true ] then
|
if [ "$vhost_backup" = true ]
|
||||||
|
then
|
||||||
echo "Backing up vhosts..." >&2
|
echo "Backing up vhosts..." >&2
|
||||||
mkdir -p $tmpdir/vhosts
|
mkdir -p $tmpdir/vhosts
|
||||||
cp -r $vhost_dir/ $tmpdir/vhosts/
|
cp -r $vhost_dir/ $tmpdir/vhosts/
|
||||||
@ -52,40 +55,49 @@ fi
|
|||||||
}
|
}
|
||||||
|
|
||||||
function logbackup {
|
function logbackup {
|
||||||
if [ "$log_backup" = true ] then
|
if [ "$log_backup" = true ]
|
||||||
|
then
|
||||||
echo "Backing up system logs..." >&2
|
echo "Backing up system logs..." >&2
|
||||||
mkdir -p $tmpdir/syslogs
|
mkdir -p $tmpdir/syslogs
|
||||||
cp /var/log/syslog $tmpdir/syslogs/
|
cp /var/log/syslog $tmpdir/syslogs/
|
||||||
cp /var/log/message $tmpdir/syslogs/
|
cp /var/log/message $tmpdir/syslogs/
|
||||||
|
|
||||||
if [ "$fail2ban_log" = true ] then
|
if [ "$fail2ban_log" = true ]
|
||||||
|
then
|
||||||
cp /var/log/fail2ban.log $tmpdir/syslogs/
|
cp /var/log/fail2ban.log $tmpdir/syslogs/
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$log_backup_web" = true] then
|
if [ "$log_backup_web" = true]
|
||||||
if [ "$apache" = true ] then
|
then
|
||||||
|
if [ "$apache" = true ]
|
||||||
|
then
|
||||||
mkdir -p $tmpdir/apachelogs
|
mkdir -p $tmpdir/apachelogs
|
||||||
cp -r /var/log/httpd $tmpdir/apachelogs
|
cp -r /var/log/httpd $tmpdir/apachelogs
|
||||||
fi
|
fi
|
||||||
if [ "$nginx" = true ] then
|
if [ "$nginx" = true ]
|
||||||
|
then
|
||||||
mkdir -p $tmpdir/nginxlogs
|
mkdir -p $tmpdir/nginxlogs
|
||||||
cp -r /var/log/nginx $tmpdir/nginxlogs
|
cp -r /var/log/nginx $tmpdir/nginxlogs
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$log_purge" = true] then
|
if [ "$log_purge" = true]
|
||||||
|
then
|
||||||
echo "Purging logs..." >&2
|
echo "Purging logs..." >&2
|
||||||
truncate -s 0 /var/log/syslog
|
truncate -s 0 /var/log/syslog
|
||||||
truncate -s 0 /var/log/message
|
truncate -s 0 /var/log/message
|
||||||
if [ "$apache" = true ] then
|
if [ "$apache" = true ]
|
||||||
|
then
|
||||||
# TODO: removal for .1.2.3 logs
|
# TODO: removal for .1.2.3 logs
|
||||||
truncate -s 0 /var/log/httpd/*
|
truncate -s 0 /var/log/httpd/*
|
||||||
fi
|
fi
|
||||||
if [ "$nginx" = true ] then
|
if [ "$nginx" = true ]
|
||||||
|
then
|
||||||
# TODO: removal for .1.2.3 logs
|
# TODO: removal for .1.2.3 logs
|
||||||
truncate -s 0 /var/log/nginx/*
|
truncate -s 0 /var/log/nginx/*
|
||||||
fi
|
fi
|
||||||
if [ "$fail2ban_log" = true ] then
|
if [ "$fail2ban_log" = true ]
|
||||||
|
then
|
||||||
truncate -s 0 /var/log/fail2ban.log
|
truncate -s 0 /var/log/fail2ban.log
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -94,17 +106,21 @@ fi
|
|||||||
}
|
}
|
||||||
|
|
||||||
function push {
|
function push {
|
||||||
if [ "rsync_push" = true ] then
|
if [ "rsync_push" = true ]
|
||||||
|
then
|
||||||
#Push - Dockerized
|
#Push - Dockerized
|
||||||
if [ "push_clean" = true ] then
|
if [ "push_clean" = true ]
|
||||||
|
then
|
||||||
rm /opt/backify-$timestamp.tar.gz
|
rm /opt/backify-$timestamp.tar.gz
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function dockerbackup {
|
function dockerbackup {
|
||||||
if [ "docker_enabled" = true] then
|
if [ "docker_enabled" = true]
|
||||||
if [ "docker_images" = true] then
|
then
|
||||||
|
if [ "docker_images" = true]
|
||||||
|
then
|
||||||
echo "Backing up Docker images..." >&2
|
echo "Backing up Docker images..." >&2
|
||||||
for i in `docker inspect --format='{{.Name}}' $(docker ps -q) | cut -f2 -d\/`
|
for i in `docker inspect --format='{{.Name}}' $(docker ps -q) | cut -f2 -d\/`
|
||||||
do container_name=$i
|
do container_name=$i
|
||||||
@ -116,7 +132,8 @@ function dockerbackup {
|
|||||||
echo "Finished" >&2
|
echo "Finished" >&2
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
if [ "docker_volumes" = true ] then
|
if [ "docker_volumes" = true ]
|
||||||
|
then
|
||||||
echo "Backing up Docker volumes..." >&2
|
echo "Backing up Docker volumes..." >&2
|
||||||
for i in `docker inspect --format='{{.Name}}' $(docker ps -q) | cut -f2 -d\/`
|
for i in `docker inspect --format='{{.Name}}' $(docker ps -q) | cut -f2 -d\/`
|
||||||
do container_name=$i
|
do container_name=$i
|
||||||
@ -131,7 +148,8 @@ function dockerbackup {
|
|||||||
echo "Finished" >&2
|
echo "Finished" >&2
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
if [ "docker_data" = true ] then
|
if [ "docker_data" = true ]
|
||||||
|
then
|
||||||
echo "Backing up container information..." >&2
|
echo "Backing up container information..." >&2
|
||||||
for i in `docker inspect --format='{{.Name}}' $(docker ps -q) | cut -f2 -d\/`
|
for i in `docker inspect --format='{{.Name}}' $(docker ps -q) | cut -f2 -d\/`
|
||||||
do container_name=$i
|
do container_name=$i
|
||||||
@ -146,7 +164,8 @@ function dockerbackup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function runbackup {
|
function runbackup {
|
||||||
if [ "enabled" = true] then
|
if [ "enabled" = true]
|
||||||
|
then
|
||||||
# step 1 : create directory
|
# step 1 : create directory
|
||||||
makedir
|
makedir
|
||||||
# step 2 : www backup
|
# step 2 : www backup
|
||||||
|
Loading…
Reference in New Issue
Block a user