Commit dcff61eb authored by root's avatar root

added backup script

parent 9d6c8d01
#!/bin/bash
backup_dir="/tmp/backups"
mkdir -p $backup_dir
echo "self backup"
cp $0 "$backup_dir/backup_created_with.sh"
echo "prepare git sync"
eval $(ssh-agent)
ssh-add /root/.ssh/appa_uebungen
ssh-add /root/.ssh/git.nwt
echo "prepare swapfile"
sw=/tmp/backup_swapfile
if [ ! -e $sw ] ; then
dd if=/dev/zero of=$sw bs=1024 count=$((5*1024*1024))
chmod 0600 $sw
mkswap $sw
fi
swapon $sw
working_dir="/tmp/git_repos"
mkdir -p $working_dir
function git_up {
# $1 src git
# $2 name
# $3 dst git
# [$4] extra remote
echo $2
if [ -e $2 ] ; then
cd $2
git pull origin
if [ ! -z "$4" ] ; then
git pull extra
fi
else
git clone $1 $2
cd $2
git remote add backup $3 && echo "remote added"
if [ ! -z "$4" ] ; then
git remote add extra $4
git pull extra
fi
fi
git push backup
}
cd $working_dir
git_up "git@git.nwt.fhstp.ac.at:is151014-old/bis15_codes.git" "bis15_codes" "git@git.clemo.xelt.co:clemo/bis15_codes.git"
cd $working_dir
git_up "git@git.nwt.fhstp.ac.at:is151014-old/AK_Uebungen.git" "AK_Uebungen" "git@git.clemo.xelt.co:clemo/AK_Uebungen.git"
cd $working_dir
git_up "git@git.nwt.fhstp.ac.at:is151014/linux-config.git" "linux-config" "git@git.clemo.xelt.co:clemo/linux-config.git"
cd $working_dir
git_up "git@git.nwt.fhstp.ac.at:wuaps/uebungen.git" "wuaps-uebungen" "git@git.clemo.xelt.co:clemo/wuaps-uebungen.git"
cd $working_dir
git_up "git@git.nwt.fhstp.ac.at:is151014/webtech-blog.git" "webtech-blog" "git@git.clemo.xelt.co:clemo/webtech-blog.git"
cd $working_dir
git_up "git@git.nwt.fhstp.ac.at:is151014/TEMPLATES.git" "TEMPLATES" "git@git.clemo.xelt.co:clemo/TEMPLATES.git"
cd $working_dir
git_up "git@git.nwt.fhstp.ac.at:NSK/nsk-bis15.git" "nsk-bis15" "git@git.clemo.xelt.co:clemo/nsk-bis15.git"
cd $working_dir
git_up "git@git.nwt.fhstp.ac.at:is151014/webtech.git" "webtech" "git@git.clemo.xelt.co:clemo/webtech.git"
cd $working_dir
git_up "git@git.nwt.fhstp.ac.at:is151014/bis15-db.git" "db-bis15" "git@git.clemo.xelt.co:clemo/db-bis15.git"
cd $working_dir
git_up "git@git.nwt.fhstp.ac.at:is151005/vmitf_uebung2.git" "malware_vertiefung_ue2" "git@git.clemo.xelt.co:clemo/vertiefung_maleware_ue2.git"
cd $working_dir
git_up "git@git.nwt.fhstp.ac.at:is151014/bssp-bis15.git" "bssp-bis15" "git@git.clemo.xelt.co:clemo/bssp-bis15.git"
cd $working_dir
git_up "git@git.nwt.fhstp.ac.at:is151032/iua.git" "iua-bis15" "git@git.clemo.xelt.co:clemo/iua-bis15.git"
cd $working_dir
git_up "git@git.nwt.fhstp.ac.at:is151032/snus.git" "snus-bis15" "git@git.clemo.xelt.co:clemo/snus-bis15.git"
cd $working_dir
git_up "git@git.nwt.fhstp.ac.at:is151014/itil-gruppe6.git" "itil-gruppe6-bis15" "git@git.clemo.xelt.co:clemo/itil-gruppe6-bis15.git"
cd $working_dir
git_up "git@git.nwt.fhstp.ac.at:is131014/C_BIS15VZ.git" "C_BIS15_VZ_tut" "git@git.clemo.xelt.co:clemo/C_BIS15VZ_TUT.git"
cd $working_dir
git_up "git@git.nwt.fhstp.ac.at:ekey/ekey-documents.git" "ekey-documents" "git@git.clemo.xelt.co:clemo/ekey-documents-backup.git"
cd $working_dir
git_up "git@git.nwt.fhstp.ac.at:ekey/ekey-tests.git" "ekey-tests" "git@git.clemo.xelt.co:clemo/ekey-tests-backup.git"
cd $working_dir
git_up "git@git.nwt.fhstp.ac.at:is151032/vmtif.git" "vertiefung-malware-bis15" "git@git.clemo.xelt.co:clemo/vertiefung-malware-bis15.git"
cd $working_dir
git_up "git@git.nwt.fhstp.ac.at:matthias.husinsky/cocktail.git" "cocktail_robo" "git@git.clemo.xelt.co:clemo/cocktail_robo.git" "git@git.nwt.fhstp.ac.at:is151014/cocktail.git"
echo "backup gitlab"
gitlab-rake gitlab:backup:create
echo "compress"
cd /var/opt/gitlab/backups
gitlab_file=$(ls -t | head -n1)
cat $gitlab_file | xz -3e -v --check=crc64 > "$backup_dir/gitlab.tar.xz" && rm $gitlab_file
echo "backup /etc /root /var"
tar -cf - /etc /root /var --exclude "/var/spool/postfix/*" 2> /dev/null | xz -3e -v --check=crc64 > "$backup_dir/general_config.tar.xz"
echo "states"
echo -e "ufw status:\n$(ufw status)\n\nblocked IPs:\n$(iptables -S | grep f2b | grep REJECT)" | xz -3e -v > "$backup_dir/status_printout.xz"
echo "swapoff"
swapoff $sw
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment