From: Vincent Vanwaelscappel Date: Wed, 19 Jul 2023 19:14:32 +0000 (+0200) Subject: wip #6145 @2 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=d6f9c9942ca3e4392776ff04fa9c44e8de45819e;p=server-backup.git wip #6145 @2 --- d6f9c9942ca3e4392776ff04fa9c44e8de45819e diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..fc87a42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +* text=auto +*.sh text eol=lf +update text eol=lf +backup text eol=lf +*_key text eol=lf +*.bat text eol=crlf diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/deployment.xml b/.idea/deployment.xml new file mode 100644 index 0000000..9bc0f3d --- /dev/null +++ b/.idea/deployment.xml @@ -0,0 +1,420 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..b658e95 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..024e797 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/server-backup.iml b/.idea/server-backup.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/server-backup.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..56c5bb7 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + C:\Users\Vincent\AppData\Roaming\Subversion + + + + + 1689791641269 + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fa99a76 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM alpine +MAINTAINER "EEA: IDM2 A-Team" + +RUN apk add --no-cache --virtual .run-deps rsync openssh tzdata curl ca-certificates bash && rm -rf /var/cache/apk/* +COPY --chmod=755 docker-entrypoint.sh / + +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["sh"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..8aa846e --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# Installation + +On the server to backup : + +Fill correctly `/etc/hostname`, the name will be used as the destination folder + +If docker is not installed : `wget https://get.docker.com -O get-docker.sh && sh get-docker.sh` + +`apt install -y git docker-composer-plugin;mkdir -p /docker/server-backup;cd /docker/server-backup;git clone git://git.cubedesigners.com/server-backup.git .;chmod 755 update;./update` \ No newline at end of file diff --git a/backup b/backup new file mode 100755 index 0000000..f25abfa --- /dev/null +++ b/backup @@ -0,0 +1,3 @@ +#!/bin/sh +name=`cat /etc/backup-hostname` +/usr/bin/rsync -av --exclude-from='/etc/backup.exclude' -e 'ssh -oStrictHostKeyChecking=no' /data/ serversbackup@dobermann.cubedesigners.com:/home/serversbackup/$name/" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..55f2b6c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,18 @@ +version: '3.3' +services: + backup: + container_name: backup + volumes: + - '/:/data/' + - '/etc/hostname:/etc/backup-hostname' + - './exclude:/etc/backup.exclude' + - './backup:/usr/local/bin/backup' + - './keys/id_rsa:/home/user/.ssh/id_rsa:ro' + - './keys/id_rsa.pub:/home/user/.ssh/id_rsa.pub:ro' + - './keys/id_rsa:/root/.ssh/id_rsa:ro' + - './keys/id_rsa.pub:/root/.ssh/id_rsa.pub:ro' + restart: unless-stopped + build: . + environment: + - CRON_TASK_1="0 */6 * * * /usr/local/bin/backup" + command: client diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..467d0bb --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,82 @@ +#!/bin/sh + +################################################################################ +# INIT +################################################################################ + +mkdir -p /root/.ssh +> /root/.ssh/authorized_keys +chmod go-rwx /root/.ssh/authorized_keys +sed -i "s/.*PasswordAuthentication .*/PasswordAuthentication no/g" /etc/ssh/sshd_config +sed -i 's/root:!/root:*/' /etc/shadow + +# Provide SSH_AUTH_KEY_* via environment variable +for item in `env`; do + case "$item" in + SSH_AUTH_KEY*) + ENVVAR=`echo $item | cut -d \= -f 1` + printenv $ENVVAR >> /root/.ssh/authorized_keys + ;; + esac +done + +# Provide CRON_TASK_* via environment variable +> /etc/crontabs/root +for item in `env`; do + case "$item" in + CRON_TASK*) + ENVVAR=`echo $item | cut -d \= -f 1` + printenv $ENVVAR >> /etc/crontabs/root + echo "root" > /etc/crontabs/cron.update + ;; + esac +done + +# Generate host SSH keys +if [ ! -e /etc/ssh/ssh_host_rsa_key.pub ]; then + ssh-keygen -A +fi + +# Generate root SSH key +if [ ! -e /root/.ssh/id_rsa.pub ]; then + ssh-keygen -q -N "" -f /root/.ssh/id_rsa +fi + +################################################################################ +# START as SERVER +################################################################################ + +if [ "$1" == "server" ]; then + AUTH=`cat /root/.ssh/authorized_keys` + if [ -z "$AUTH" ]; then + echo "==================================================================================" + echo "ERROR: No SSH_AUTH_KEY provided, you'll not be able to connect to this container. " + echo "==================================================================================" + exit 1 + fi + + SSH_PARAMS="-D -e -p ${SSH_PORT:-22} $SSH_PARAMS" + echo "================================================================================" + echo "Running: /usr/sbin/sshd $SSH_PARAMS " + echo "================================================================================" + + exec /usr/sbin/sshd -D $SSH_PARAMS +fi + +echo "Please add this ssh key to your server /home/user/.ssh/authorized_keys " +echo "================================================================================" +echo "`cat /root/.ssh/id_rsa.pub`" +echo "================================================================================" + +################################################################################ +# START as CLIENT via crontab +################################################################################ + +if [ "$1" == "client" ]; then + exec /usr/sbin/crond -f +fi + +################################################################################ +# Anything else +################################################################################ +exec "$@" diff --git a/exclude b/exclude new file mode 100644 index 0000000..a05747a --- /dev/null +++ b/exclude @@ -0,0 +1,41 @@ +/tmp +/home/s +/mnt +/home/var/log +/var/cache +/home/log +/var/log +/dev +/media +/nonexistent +/selinux +/sys +/home/extranet/www/fluidbook/cache +/home/extranet/www/fluidbook/packager +/etc/webmin/system-status/history +/proc +/usr/share/doc +/run +/data/amarcord +*/framework/cache +*/framework/data/temp +/home/hbackup/tmp +/snap +/home/var/lib/amavis/tmp +/home/root/.composer/cache +/home/maisondelamouche/www/var/cache +/home/maisondelamouche/www/var/session +/docker/maisonmouche/www/var/cache +/docker/maisonmouche/www/var/session +/var/lib/php/sessions +/home/var/lib/php/sessions +*/framework/sessions +/home/tmp +/var/tmp +/data1/temp +/data/temp +/data1/extranet/.cache +data1/extranet/www/fluidbook/cache +data1/extranet/www/fluidbook/packager +/data/backup +/boot \ No newline at end of file diff --git a/update b/update new file mode 100755 index 0000000..db3737b --- /dev/null +++ b/update @@ -0,0 +1,12 @@ +#!/bin/bash +cd /docker/server-backup +git config --global --add safe.directory /docker/server-backup +git fetch --all +git reset --hard origin/master +git stash +git pull origin master +chmod 755 /docker/server-backup/ssh +chmod 600 /docker/server-backup/ssh/id_rsa +DOCKER_BUILDKIT=1 docker compose build +docker compose down +docker compose up -d \ No newline at end of file