# Change log of
+
+## V0.3.0: improvements
+
+## V0.2.0: first working version as nest1
+
## V0.1.0: first working version as ansknife
--- /dev/null
+---
+# Maintains the cron jobs for the nest1 server
+- hosts: all
+ vars:
+ hostname: "{{ inventory_hostname }}"
+ path_script: /usr/local/bin
+ path_script_local: "{{ path_script }}/{{ hostname }}"
+ hostname_short: Nest1
+ vars_files:
+ - ../var/common.yaml
+ tasks:
+ - name: Creates a cron file for clearing the swap files
+ ansible.builtin.cron:
+ name: clear the swap files
+ minute: "42"
+ hour: "23"
+ user: root
+ job: "{{ path_script_local }}/ClearSwap -q"
+ cron_file: ClearSwap
+ - name: Save the ownership of a file tree in the file .owner.list
+ ansible.builtin.cron:
+ name: store the ownership of a file tree
+ minute: "39"
+ hour: "23"
+ user: root
+ job: "{{ path_script_local }}/SaveOwner.sh -q"
+ cron_file: SaveOwner
+ when: neverEver is defined
+ - name: Build a a server specific backup
+ ansible.builtin.cron:
+ name: builds the backup
+ minute: "19"
+ hour: "0"
+ user: root
+ job: "{{ path_script_local }}/{{ hostname_short }Backup -q"
+ cron_file: "{{ hostname_short }}Backup"
+ when: neverEver is defined
+ - name: Save the databases
+ ansible.builtin.cron:
+ name: Save the web applications
+ minute: "29"
+ hour: "0"
+ user: root
+ job: "{{ path_script_local }}/SaveDatabases -q"
+ cron_file: SaveDatabases
--- /dev/null
+---
+# Installs the scripts usesed for the cron jobs
+#
+# needesd facts (variables):
+# hostname: the name of the remote server
+# optional facts
+# hostname_short: the short name of the remote server. Default: prefix of hostname
+- hosts: all
+ vars:
+ hostname: "{{ inventory_hostname }}"
+ path_script: /usr/local/bin
+ path_script_local: "{{ path_script }}/{{hostname}}"
+ vars_files:
+ - ../var/common.yaml
+ tasks:
+ - name: create facts
+ ansible.builtin.set_fact:
+ hostname_short: "{{ hostname.split('.')[0] }}"
+ when: hostname_short is not defined
+ - name: install the scripts in {{ path_script_local }}
+ ansible.builtin.copy:
+ src: ../templates.local/local_bin/{{ item }}
+ dest: "{{ path_script_local }}/{{ item }}"
+ mode: "0740"
+ with_items:
+ - CreateSysInfo
+ - SaveOwner
+ - ClearSwap
+ - SaveDatabases
+ - "{{ hostname_short }}Backup"
\ No newline at end of file
--- /dev/null
+../../ansknife/tasks.templates/t_sysinfo_create.yaml
\ No newline at end of file
--- /dev/null
+#! /bin/bash
+LOG=/var/log/local/clearswap.log
+VERBOSE=-v
+test "$1" = -q && VERBOSE=
+PATH=/bin:/usr/bin:/usr/sbin
+function Log(){
+ local msg=$(date "+%Y.%m.%d-%H:%M:%S: $1")
+ test -n "$VERBOSE" && echo $msg
+ echo >>$LOG "$msg"
+}
+
+Log "swapoff:"
+info=$(swapoff -a)
+Log "logoff result: $info"
+info=$(swapon -a)
+Log "logon result: $info"
--- /dev/null
+#! /bin/bash
+# Ansible controlles. Do not change on remote server.
+#
+# Save structure data and configuration of the remove server nest1
+DIR_INFO=/srv/www/sys.info/nest1.gemeinwohl-gesellschaft.de
+BTRFS_FS=
+MK_HOME_TAR=yes
+Home_TAR_EXCLUDE="--exclude=www"
+USE_ZFS=no
+EXCLUDE_HOME="--exclude=jails"
+TAG_FILE=.do.not.save
+VERBOSE=-v
+export PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
+test "$1" = -q && VERBOSE=
+mkdir -p $DIR_INFO
+function Packages(){
+ test "$VERBOSE" = -v && echo "= packages"
+ dpkg -l | sort > $DIR_INFO/packets.installed.txt
+ apt-mark showmanual | sort >$DIR_INFO/packets.manually.txt
+ cp /var/log/apt/history.log $DIR_INFO/apt.history.txt
+}
+function Mount(){
+ test "$VERBOSE" = -v && echo "= mount"
+ mount | grep /dev/ | egrep -v "devpts|hugetlbfs|tmpfs|mqueue" > $DIR_INFO/mount.txt
+}
+function Devices(){
+ test "$VERBOSE" = -v && echo "= device info"
+ blkid > $DIR_INFO/blkid.txt
+ lsblk > $DIR_INFO/lsblk.txt
+ free > $DIR_INFO/free.txt
+ df -h | grep -v docker > $DIR_INFO/df.txt
+ test "$VERBOSE" = -v && echo "= btrfs"
+ rm -f $DIR_INFO/btrfs.subvols.txt
+ if [ -n "$BTRFS_FS" ]; then
+ for fs in $BTRFS_FS; do
+ if [ -d $media/$fs ]; then
+ echo "= $fs: >>$DIR_INFO/btrfs.subvols.txt"
+ btrfs subvol list /media/$fs | grep -v snapshot >> $DIR_INFO/btrfs.subvols.txt
+ fi
+ done
+ fi
+ test "$VERBOSE" = -v && echo "= fdisk"
+ fdisk -l > $DIR_INFO/fdisk.txt
+}
+function SystemD(){
+ test "$VERBOSE" = -v && echo "= systemctl"
+ systemctl list-unit-files > $DIR_INFO/systemd.files.txt
+ systemctl list-units > $DIR_INFO/systemd.units.txt
+}
+function Trees(){
+ test "$VERBOSE" = -v && echo "= directories"
+ for dir in etc usr/local/bin var/spool/cron/crontabs var/log; do
+ name=${dir//\//_}
+ cd /$dir
+ test -n "$VERBOSE" && echo "= $(pwd)"
+ opt=
+ trg=$DIR_INFO/$dir
+ mkdir -p $trg
+ #test $dir = var/log && opt=--newer-mtime=$(date --date='yesterday' +%Y%m%d)
+ #tar czf $DIR_INFO/$name.tgz . $opt
+ test $dir = var/log && opt="--exclude=journal --exclude=*.log.*gz"
+ test $dir = etc && opt="--exclude=.git --exclude=sysinit.target.wants --exclude=multi-user.target.wants"
+ rsync -au $VERBOSE --delete-excluded --delete $opt ./ $trg
+ test "$VERBOSE" = -v && echo "= chown $dir"
+ find $trg -uid 0 -exec chown bupsupply "{}" \; >/dev/null 2>&1
+ done
+ if [ $MK_HOME_TAR = yes ]; then
+ test "$VERBOSE" = -v && echo "= home"
+ pushd /home >/dev/null 2>&1
+ tar czf $DIR_INFO/home.tgz $EXCLUDE_HOME --exclude-tag-all=$TAG_FILE .
+ popd >/dev/null 2>&1
+ test "$VERBOSE" = -v && ls -ld $DIR_INFO/home.tgz
+ fi
+}
+function Zfs(){
+ if [ $USE_ZFS = yes ]; then
+ test "$VERBOSE" = -v && echo "= ZFS"
+ local fn=$DIR_INFO/zfs.info.txt
+ echo "== zfs list" >$fn
+ zfs list >>$fn
+ echo "== zpool list" >>$fn
+ zpool list >>$fn
+ echo "== zpool status" >>$fn
+ zpool status >>$fn
+ echo "== zfs list -t snapshot" >>$fn
+ zfs list -t snapshot >>$fn
+ fi
+}
+function DoIt(){
+ local debug=
+ $debug Packages
+ $debug Mount
+ $debug Devices
+ $debug SystemD
+ $debug Trees
+ $debug Zfs
+}
+DoIt
--- /dev/null
+#! /bin/bash
+BASE_DIR=/srv/www
+BASE_WEBAPPS=/etc/ansknife/webapps.d
+VERBOSE=-v
+test "$1" = -q && VERBOSE=
+PATH=/bin:/usr/bin
+function SaveOne(){
+ local domain=$1
+ if [ -e $BASE_WEBAPPS/$domain.conf ]; then
+ . $BASE_WEBAPPS/$domain.conf
+ if [ -n "$db_name" ]; then
+ local sql=$BASE_DIR/$domain/db/$domain.sql.gz
+ mysqldump -u $db_user "-p$db_password" $db_name | gzip > $sql
+ test -n "$VERBOSE" && ls -ld $sql
+ fi
+ fi
+}
+function SaveAll(){
+ cd $BASE_DIR
+ for domain in *; do
+ if [ -d $BASE_DIR/$domain/db ]; then
+ SaveOne $domain
+ fi
+ done
+}
+SaveAll
\ No newline at end of file
--- /dev/null
+#! /bin/bash
+DIRS="/srv/www"
+# DIRS="/home /srv/wwww"
+VERBOSE=5
+PATH=/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin
+test "$1" = -q && VERBOSE=0
+
+function SaveOneDir(){
+ local dir=$1
+ test $VERBOSE != 0 && echo "= $dir"
+ pushd $dir >/dev/null 2>&1
+ fileknife -l$VERBOSE owner . .owner.list
+ gzip -q -f .owner.list
+ test $VERBOSE != 0 && ls -l $(pwd)/.owner.list*
+ popd >/dev/null 2>&1
+}
+function SaveSubdirs(){
+ local base=$1
+ cd $base
+ for dir in *; do
+ if [ -d $dir ]; then
+ SaveOneDir $base/$dir
+ fi
+ done
+}
+
+function SaveAll(){
+ for dir in $DIRS; do
+ SaveSubdirs $dir
+ done
+}
+#SaveAll
+
--- /dev/null
+#! /bin/bash
+
+# currently we do nothing
\ No newline at end of file