Skip to content

Instantly share code, notes, and snippets.

@Reiner030
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Reiner030/4b602289320f3c2ed4e7 to your computer and use it in GitHub Desktop.
Save Reiner030/4b602289320f3c2ed4e7 to your computer and use it in GitHub Desktop.
Virtualbox + Vagrant Test Setup for ReaR
ssh-rsa AAAAB3..... your ssh pubkey line
- /root/.cache
- /root/.ccache
-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----
#!/bin/bash
# helpful for debugging
#!/bin/bash -x
# Github Repository_URL of ReaR:
# GIT_REPO="https://github.com/rear/rear.git"
GIT_REPO="https://github.com/Reiner030/rear.git"
# Debian Repository_URL:
DEBIAN_REPO="http://ftp.de.debian.org/debian"
# setup branch if different from "master"
#BRANCH="master"
BRANCH="vagrant-integration"
# additional Debian Packages to install:
# tyl0re's version is using now needing additonal packages
#==> default: == Prepare manual ==
ADD_PACKAGES="asciidoc xmlto"
# Duply target:
## file:// is not working because of missing vbosf support:
## TARGET="file:///vagrant/backupspace/rear-test"
# TARGET="s3://s3.amazonaws.com/<bucket>/rear-test"
TARGET="ssh://duply@192.168.10.41/rear-test"
# for some backends you need TARGET_USER/PASS:
#TARGET_USER="AWS_ACCESS_KEY_ID"
#TARGET_PASS="AWS_SECRET_ACCESS_KEY"
#TARGET_USER=""
#TARGET_PASS=""
# if you need ssh pubkey auth set key filename.
# default search in local folder for it
SSH_DUPLY_KEY='id_rsa_duply'
SSH_DUPLY_KNOWN_HOSTS='known_hosts_duply'
# To get access in ISO image we must include our keylines
## is there a way to include external ~/.ssh/authorized
## or ~/.ssh/id_*.pub lines by Vagrantfile?
SSH_ADMIN_PUBKEY='authorized_keys'
# easy modification of backup volume size (default: "25" MB)
VOLSIZE=250
# setup path so that /root/.cache/duplicity is not used
ARCH_DIR=/var/cache/duplicity
echo Provisioning:
sed -i -e "s/packer-virtualbox-iso/rear-test/g" \
/etc/hostname \
/etc/mailname \
/etc/hosts \
/etc/exim4/update-exim4.conf.conf \
/etc/ssh/ssh_host_rsa_key.pub
hostname -F /etc/hostname
echo
echo
echo setup rear/duply/duplicity/git/debhelper/cpulimit:
echo ======================================================
if test ! `grep -q "$DEBIAN_REPO" /etc/apt/sources.list`
then
sed -i -e "s#http://http.us.debian.org/debian#$DEBIAN_REPO#" \
/etc/apt/sources.list
DEBIAN_FRONTEND=noninteractive aptitude update
fi
DEBIAN_FRONTEND=noninteractive aptitude -y install \
duply duplicity python-boto ncftp python-pexpect \
python-cloudfiles lftp python-gdata tahoe-lafs \
python-paramiko python-gobject-2 \
git debhelper cpulimit $ADD_PACKAGES
echo ======================================================
echo
echo
echo checkout $GIT_REPO and create package:
echo ======================================================
cd /vagrant
test -d rear || git clone $GIT_REPO
cd rear
GIT_REPO_FOUND=`git remote -v | sed -ne "s/origin\t\(.*\) (fetch)/\1/p"`
if test "$GIT_REPO_FOUND" != "$GIT_REPO"
then
echo "expected repository $GIT_REPO "
echo "but found $GIT_REPO_FOUND ."
echo "Moving actual Repo and checkout new one..."
REAR_VERSION=`sed -ne "s/^rear (\(.*\)) .*/\1/p" \
packaging/debian/changelog | head -1`
cd ..
mv rear rear.wrong.$$
mv rear_${REAR_VERSION}_all.deb rear_${REAR_VERSION}_all.deb.wrong.$$
if test -n "$BRANCH" && "$BRANCH" != "master"
then
echo "branch: $BRANCH:"
git clone $GIT_REPO --branch $BRANCH
else
git clone $GIT_REPO
fi
cd rear
echo "Continue normal with correct repository/branch... ;)"
else
# check for remote branch: git branch -r | grep -q " origin/$BRANCH"
if test `git branch -l | grep -q "* $BRANCH"`
then
echo -n "Actual wrong local branch found: "
git branch -l | sed -e "s#* \($BRANCH\)#\"\1\"#"
echo switching to branch "$BRANCH" .
git checkout -b $BRANCH origin/$BRANCH
fi
fi
OUTPUT=`git pull`
echo $OUTPUT
REAR_VERSION=`sed -ne "s/^rear (\(.*\)) .*/\1/p" \
packaging/debian/changelog | head -1`
if test "$OUTPUT" == "Already up-to-date." && \
test -f ../rear_${REAR_VERSION}_all.deb
then
echo "rear $REAR_VERSION package already created"
else
make clean
make deb
echo ======================================================
echo
echo
echo install and created package with dependencies:
echo ======================================================
REAR_VERSION=`sed -ne "s/^rear (\(.*\)) .*/\1/p" \
packaging/debian/changelog | head -1`
echo "rear $REAR_VERSION found."
fi
DEBIAN_FRONTEND=noninteractive dpkg -I ../rear_${REAR_VERSION}_all.deb | \
sed -n -e "s/^ Depends: //p" | \
sed -e "s/,//g" | \
xargs aptitude -y install
dpkg -i ../rear_${REAR_VERSION}_all.deb
echo ======================================================
echo
echo
echo setup rear and duply config and removing previous backup files
echo ======================================================
if test `echo $TARGET | grep -qe "^file://"`
then
BACKUP_PATH=`echo $TARGET | sed -e "s#^file://##"`
mkdir -p `dirname $BACKUP_PATH`
test -d $BACKUP_PATH && \
rm -rf $BACKUP_PATH
fi
test -f /vagrant/rear-rear-test.iso && \
rm -f /vagrant/rear-rear-test.iso
grep -q ^BACKUP /etc/rear/local.conf || \
echo BACKUP=DUPLICITY >> /etc/rear/local.conf
mkdir -p $ARCH_DIR
mkdir -p /etc/duply
# remove of config helpful for sed rewriting
#rm -rf /etc/duply/rear-test
test -d /etc/duply/rear-test || duply rear-test create
sed -i -e 's/^\(GPG_KEY\)=/#\1=/' \
-e "s/^#\?\(VOLSIZE\)=.*/\1=$VOLSIZE/" \
-e 's/^#\(DUPL_PARAMS="$DUPL_PARAMS --volsize $VOLSIZE "\)/\1/' \
-e "s/^#\?\(GPG_PW\)=.*/\1='trivialpass'/" \
-e "s#^\#\?\(TARGET\)=.*#\1='$TARGET'#" \
-e "s#^\#\?\(SOURCE\)=.*#\1='/'#" \
-e "s#^\#\?\(ARCH_DIR\)=.*#\1='$ARCH_DIR'#" \
/etc/duply/rear-test/conf
test -n "$TARGET_USER" && \
sed -i -e "s/^#?\(TARGET_USER\)=.*/#\1=\"$TARGET_USER\"/" \
/etc/duply/rear-test/conf
test -n "$TARGET_PASS" && \
sed -i -e "s/^#?\(TARGET_PASS\)=.*/#\1=\"$TARGET_PASS\"/" \
/etc/duply/rear-test/conf
test -f /etc/duply/rear-test/exclude || \
cat > /etc/duply/rear-test/exclude <<END
- /dev
- /proc
- /sys
- /tmp
- /home/*/.cache
- /home/*/.ccache
- /media
- /mnt
- /root/.cache
- /root/.ccache
- /run
- /selinux
- /sys
- /srv
- /tmp
- /vagrant/*
- /var/cache/*/*
- /lost+found
- /*/lost+found
- /var/run
- /var/tmp
- $ARCH_DIR
END
test -f /etc/duply/rear-test/pre || echo '/usr/bin/test -x /usr/bin/cpulimit && kill `pgrep -f "cpulimit -e gpg"` || true' > /etc/duply/rear-test/pre && chmod +x /etc/duply/rear-test/pre
test -f /etc/duply/rear-test/post || echo '/usr/bin/test -x /usr/bin/cpulimit && nohup cpulimit -e gpg -l 20 -b > /tmp/cpulimit-$(date "+%F").log 2>&1 || true' > /etc/duply/rear-test/post && chmod +x /etc/duply/rear-test/post
mkdir -p /root/.ssh
chmod -R 755 /root/.ssh
if test -n "$SSH_DUPLY_KEY" && test -f /vagrant/$SSH_DUPLY_KEY
then
cp /vagrant/$SSH_DUPLY_KEY /root/.ssh/id_rsa
chmod -R 400 /root/.ssh/id_rsa
fi
if test -n "$SSH_ADMIN_PUBKEY" && test -f /vagrant/$SSH_ADMIN_PUBKEY
then
cp /vagrant/$SSH_ADMIN_PUBKEY /root/.ssh/authorized_keys
chmod -R 600 /root/.ssh/authorized_keys
fi
if test -n "$SSH_DUPLY_KNOWN_HOSTS" && test -f /vagrant/$SSH_DUPLY_KNOWN_HOSTS
then
cp /vagrant/$SSH_DUPLY_KNOWN_HOSTS /root/.ssh/known_hosts
chmod -R 644 /root/.ssh/known_hosts
fi
echo ======================================================
echo
echo
echo checking duply setup
echo ======================================================
duply rear-test status
DUPLY_SETUP=$?
echo ======================================================
if test $DUPLY_SETUP -gt 0
then
echo There is an error with duply backup setup.
echo
echo You can run provisioning again with "vagrant provision backup"
echo Login into VM is available with "vagrant ssh backup".
return $DUPLY_SETUP
else
echo ======================================================
echo
echo
echo creating rear backup
rear mkbackup -vv
cp /var/lib/rear/output/rear-rear-test.iso /vagrant
echo ======================================================
echo
echo You can run provisioning again with "vagrant provision backup" if needed.
echo Login into VM is available with "vagrant ssh backup".
fi
# -*- mode: ruby -*-
# vi: set ft=ruby :
## to use this Vagrantfile you need:
## Virtualbox: http://www.virtualbox.org
## Vagrant: http://www.vagrantup.com
## and if you need cleanup scripts for e.g. additional external destroy
## functionality ( https://github.com/emyl/vagrant-triggers ) run:
# vagrant plugin install vagrant-triggers
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
# "path:" content:
# https://docs.vagrantup.com/v2/provisioning/shell.html
#REAR_BACKUP_SETUP="http://provision.url/backup.sh"
# "inline:" content:
$REAR_BACKUP_SETUP = <<END
chmod +x /vagrant/provisioning-rear-backup.sh
/vagrant/provisioning-rear-backup.sh
END
# "path:" content:
#REAR_RECOVER_SETUP="http://provision.url/recover.sh"
# "inline:" content:
$REAR_RECOVER_SETUP = <<END
#chmod +x /vagrant/provisioning-rear-recover.sh
#/vagrant/provisioning-rear-recover.sh
echo "After boot and runninc ReaR script in GUI mode you can go into"
echo "rear shell, login as root and starting there '/usr/sbin/sshd'."
echo "Then you can access it with ssh root@127.0.0.1 -p 2122"
END
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
## own images with special needs for testing can be easily created
## e.g. with http://packer.io
# Image: Debian 7.6:
# https://vagrantcloud.com/mokote/boxes/debian-7
config.vm.box = "mokote/debian-7"
# Image: Ubuntu Trusty :
# https://vagrantcloud.com/???
#config.vm.box = "???/???"
# Image: CentOS :
# https://vagrantcloud.com/???
#config.vm.box = "???/???"
# Image: Fedora :
# https://vagrantcloud.com/???
#config.vm.box = "???/???"
# http://stackoverflow.com/questions/17845637/vagrant-default-name
config.vm.define "backup" , primary: true, autostart: true do |backup|
backup.vm.network :forwarded_port, guest: 22, host: 2222, id: "ssh", disabled: true
backup.vm.network :forwarded_port, guest: 22, host: 2022, auto_correct: true
#backup.vm.network :private_network, ip: "192.168.1.2"
backup.vm.provision "shell", inline: $REAR_BACKUP_SETUP, run: "always"
#backup.vm.provision "shell", inline: $REAR_BACKUP_SETUP
backup.vm.provider :virtualbox do |backup_prov|
# backup_prov.memory = 1024
# backup_prov.cpus = 2
end
# https://docs.vagrantup.com/v2/provisioning/file.html
# The SSH user can be determined by running vagrant ssh-config, and defaults to "vagrant".
# config.vm.provision "file", source: "~/.gitconfig", destination: ".gitconfig"
end
# if you want 1st only backup up then you can setup recover to autostart:false:
#config.vm.define "recover", autostart: false do |recover|
config.vm.define "recover" do |recover|
recover.vm.network :forwarded_port, guest: 22, host: 2222, id: "ssh", disabled: true
recover.vm.network :forwarded_port, guest: 22, host: 2122, auto_correct: true
#recover.vm.network :private_network, ip: "192.168.1.3"
#recover.vm.provision "shell", inline: "$REAR_RECOVER_SETUP"
#recover.vm.provision "shell", path: "$REAR_RECOVER_SETUP"
recover.ssh.username = "root"
recover.ssh.private_key_path = "~/.ssh/id_rsa"
recover.vm.provider :virtualbox do |recover_prov|
recover_prov.gui = true
# https://docs.vagrantup.com/v2/virtualbox/configuration.html
# http://superuser.com/questions/741734/virtualbox-how-can-i-add-mount-an-iso-image-file-from-command-line
recover_prov.customize ["storageattach", :id, "--storagectl", "IDE Controller",
"--port", "0", "--device", "1", "--type", "dvddrive",
"--medium", "rear-rear-test.iso"]
recover_prov.customize ["modifyvm", :id, "--boot1", "DVD", "--boot2", "disk",
"--boot3", "none", "--boot4", "none"]
# recover_prov.memory = 1024
# recover_prov.cpus = 2
end
end
## here needed: vagrant plugin install vagrant-triggers
#config.trigger.after :destroy do
# run "rm -rf backupspace rear*"
#end
# => should only run when both machines where destroyed ?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment