second commit
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
|
||||
case $1 in
|
||||
minute) ;;
|
||||
daily) ;;
|
||||
*) echo "expected [minute|daily]" && exit 1 ;;
|
||||
esac
|
||||
|
||||
SELECTOR=$1
|
||||
|
||||
for i in /var/www/cagettepei/*; do
|
||||
if [[ -d $i ]]; then
|
||||
cd "$i/www" || echo "Folder not found: $i/www"
|
||||
echo "cron-$SELECTOR in: $i"
|
||||
neko index.n cron/$SELECTOR
|
||||
echo
|
||||
fi
|
||||
done
|
||||
@@ -0,0 +1,8 @@
|
||||
Listen {{ env.APP_PORT }}
|
||||
<VirtualHost *:{{ env.APP_PORT }}>
|
||||
DirectoryIndex index.n
|
||||
DocumentRoot /var/www/cagettepei/{{env.APP_NAME}}/www/
|
||||
|
||||
ErrorLog ${APACHE_LOG_DIR}/cagettepei/{{env.APP_NAME}}/debug.log
|
||||
ErrorLogFormat "[%{uc}t] %M"
|
||||
</VirtualHost>
|
||||
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Run batch cagettepei every day
|
||||
|
||||
[Service]
|
||||
User=www-data
|
||||
SyslogIdentifier=cagettepei
|
||||
ExecStart=/var/www/cagettepei/cagettepei-batch daily
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Timer for batch cagettepei every day
|
||||
Requires=apache2.service
|
||||
|
||||
[Timer]
|
||||
OnCalendar=daily
|
||||
Unit=cagettepei-batch-day.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Run batch cagettepei every minute
|
||||
|
||||
[Service]
|
||||
User=www-data
|
||||
SyslogIdentifier=cagettepei
|
||||
ExecStart=/var/www/cagettepei/cagettepei-batch minute
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Timer for batch cagettepei every minute
|
||||
Requires=apache2.service
|
||||
|
||||
[Timer]
|
||||
OnCalendar=minutely
|
||||
Unit=cagettepei-batch-minute.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
@@ -0,0 +1,23 @@
|
||||
server {
|
||||
listen {{ APP_PORT }} default_server;
|
||||
|
||||
root /var/www/{{APP_NAME}}/htdocs; # Check this
|
||||
error_log /var/log/nginx/{{APP_NAME}}/error.log;
|
||||
|
||||
index index.php index.html index.htm;
|
||||
charset utf-8;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.php;
|
||||
}
|
||||
|
||||
location ~ [^/]\.php(/|$) {
|
||||
client_max_body_size 50M;
|
||||
try_files $uri =404;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
fastcgi_read_timeout 600;
|
||||
include fastcgi_params;
|
||||
fastcgi_pass unix:/var/run/php/php{{PHP_VERSION}}-fpm.sock;
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1,17 @@
|
||||
[options]
|
||||
data_dir = /home/odoo/data-{{ APP_NAME }}
|
||||
|
||||
xmlrpc_port = {{ APP_PORT }}
|
||||
longpolling_port = {{ LONG_PORT }}
|
||||
|
||||
db_host = ct1.lxd
|
||||
db_name = odoo12-{{ APP_NAME }}
|
||||
db_user = odoo12-{{ APP_NAME }}
|
||||
db_password = odoo12-{{ APP_NAME }}
|
||||
list_db = {{ target != 'prod'}}
|
||||
|
||||
workers = 2
|
||||
db_maxconn = 10
|
||||
db_filter = .*
|
||||
syslog = True
|
||||
proxy_mode = True
|
||||
@@ -0,0 +1,14 @@
|
||||
[Unit]
|
||||
Description=Odoo12 {{ APP_NAME }}
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
SyslogIdentifier=odoo12-{{ APP_NAME }}
|
||||
PermissionsStartOnly=true
|
||||
User=odoo
|
||||
Group=odoo
|
||||
ExecStart=/home/odoo/venv/bin/python3 /home/odoo/odoo12/odoo-bin -c /etc/odoo12/{{ APP_NAME }}.conf
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
|
||||
CLIENT=$1
|
||||
ADDON=$2
|
||||
|
||||
function usage() {
|
||||
echo 'usage: <CLIENT> <ADDON>'
|
||||
exit 1
|
||||
}
|
||||
|
||||
# VERIFICATION
|
||||
|
||||
[[ -z "$CLIENT" || -z "$ADDON" ]] && usage
|
||||
[[ ! -d "/home/odoo/data-${CLIENT}" ]] && echo "unknown CLIENT <${CLIENT}>, should exist in folder /home/odoo/data-..." && exit 2
|
||||
|
||||
URL="https://pypi.org/project/odoo12-addon-${ADDON}/"
|
||||
curl --output /dev/null --silent --head --fail "${URL}"
|
||||
[[ $? -ne 0 ]] && echo "unknown ADDON <${ADDON}>, should be downloadable from: ${URL}" && exit 3
|
||||
|
||||
[[ -d "/home/odoo/data-${CLIENT}/addons/12.0/${ADDON}" ]] && echo "ADDON <${ADDON}> already exists, consider removing manually!" && exit 4
|
||||
|
||||
# ACTION
|
||||
|
||||
package=$(curl -Ls ${URL} | rg '<a href="(https://files.pythonhosted.org/.*)">' -r '$1')
|
||||
wget $package -O /tmp/package.zip
|
||||
rm /tmp/ADDON -rf && mkdir /tmp/ADDON
|
||||
unzip /tmp/package.zip 'odoo/addons/*' -d /tmp/ADDON/
|
||||
chown -R odoo:odoo /tmp/ADDON/
|
||||
mv /tmp/ADDON/odoo/addons/* /home/odoo/data-${CLIENT}/addons/12.0/
|
||||
|
||||
echo "FORCE RELOADING ADDONS with: ./web?debug#menu_id=48&action=36"
|
||||
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
CLIENT=$1
|
||||
ADDON=$2
|
||||
|
||||
function usage() {
|
||||
echo 'usage: <CLIENT> <ADDON>'
|
||||
exit 100
|
||||
}
|
||||
|
||||
# VERIFICATION
|
||||
|
||||
[[ -z "$CLIENT" || -z "$ADDON" ]] && usage
|
||||
[[ ! -d "/home/odoo/data-${CLIENT}" ]] && echo "unknown CLIENT <${CLIENT}>, should exist in folder /home/odoo/data-..." && exit 2
|
||||
|
||||
URL="https://pypi.org/project/odoo-addon-${ADDON}/"
|
||||
curl --output /dev/null --silent --head --fail "${URL}"
|
||||
[[ $? -ne 0 ]] && echo "unknown ADDON <${ADDON}>, should be downloadable from: ${URL}" && exit 3
|
||||
|
||||
[[ -d "/home/odoo/data-${CLIENT}/addons/15.0/${ADDON}" ]] && echo "ADDON <${ADDON}> already exists, consider removing manually!" && exit 4
|
||||
|
||||
# ACTION
|
||||
|
||||
package=$(curl -Ls "$URL" | rg '<a href="(https://files.pythonhosted.org/.*)">' -r '$1')
|
||||
wget $package -O /tmp/package.zip
|
||||
rm /tmp/ADDON -rf && mkdir /tmp/ADDON
|
||||
unzip /tmp/package.zip 'odoo/addons/*' -d /tmp/ADDON/
|
||||
real_name=$(unzip -l /tmp/package.zip | head -n4 | tail -n1 | cut -d'/' -f3)
|
||||
chown -R odoo:odoo /tmp/ADDON/
|
||||
mv /tmp/ADDON/odoo/addons/* "/home/odoo/data-$CLIENT/addons/15.0/"
|
||||
|
||||
# ADD
|
||||
su odoo -c "python3.9 /home/odoo/odoo15/odoo-bin -c /etc/odoo15/$CLIENT.conf -i $real_name -d odoo15-$CLIENT --worker=0 --stop-after-init"
|
||||
@@ -0,0 +1,17 @@
|
||||
[options]
|
||||
data_dir = /home/odoo/data-{{ APP_NAME }}
|
||||
|
||||
xmlrpc_port = {{ APP_PORT }}
|
||||
longpolling_port = {{ LONG_PORT }}
|
||||
|
||||
db_host = ct1.lxd
|
||||
db_name = odoo15-{{ APP_NAME }}
|
||||
db_user = odoo15-{{ APP_NAME }}
|
||||
db_password = odoo15-{{ APP_NAME }}
|
||||
list_db = {{ target != 'prod'}}
|
||||
|
||||
workers = 2
|
||||
db_maxconn = 10
|
||||
db_filter = .*
|
||||
syslog = True
|
||||
proxy_mode = True
|
||||
@@ -0,0 +1,14 @@
|
||||
[Unit]
|
||||
Description=Odoo15 {{ APP_NAME }}
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
SyslogIdentifier=odoo15-{{ APP_NAME }}
|
||||
PermissionsStartOnly=true
|
||||
User=odoo
|
||||
Group=odoo
|
||||
ExecStart=python3.9 /home/odoo/odoo15/odoo-bin -c /etc/odoo15/{{ APP_NAME }}.conf
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
|
||||
function detectWordpress() {
|
||||
local result=$(pwd)
|
||||
while [[ ! ("$result" == / || -f "$result/wp-config.php") ]]; do
|
||||
result=$(dirname "$result")
|
||||
done
|
||||
|
||||
if [[ "$result" == / ]]; then
|
||||
echo >&2 "no WORDPRESS detected from current folder <$(pwd)>!"
|
||||
exit 100
|
||||
fi
|
||||
|
||||
echo "$result"
|
||||
}
|
||||
|
||||
## MAIN
|
||||
## ----
|
||||
|
||||
set -Eeuo pipefail
|
||||
WP_BASE=$(detectWordpress)
|
||||
WP_CONFIG="$WP_BASE/wp-config.php"
|
||||
DB_HOST=$(grep DB_HOST $WP_CONFIG | cut -d"'" -f4)
|
||||
DB_NAME=$(grep DB_NAME $WP_CONFIG | cut -d"'" -f4)
|
||||
DB_USER=$(grep DB_USER $WP_CONFIG | cut -d"'" -f4)
|
||||
DB_PASSWORD=$(grep DB_PASSWORD $WP_CONFIG | cut -d"'" -f4)
|
||||
TODAY=$(date +%F)
|
||||
BACKUP_DIR="/mnt/SHARED/wordpress-backup/$DB_NAME-$TODAY"
|
||||
|
||||
[[ -d "$BACKUP_DIR" ]] && find "$BACKUP_DIR" -mindepth 1 -delete || mkdir -p "$BACKUP_DIR"
|
||||
|
||||
echo -n "backing up database..."
|
||||
mariadb-dump -h "$DB_HOST" -u "$DB_NAME" -p"$DB_PASSWORD" "$DB_NAME" | gzip >"$BACKUP_DIR/$DB_NAME".mariadb.gz
|
||||
echo OK
|
||||
|
||||
echo -n "compressing as tar.gz the wp-content folder ..."
|
||||
tar -czvf "$BACKUP_DIR/wp-content.tgz" -C "$WP_BASE" wp-content
|
||||
echo OK
|
||||
|
||||
echo -n "copying wp-config.php file ..."
|
||||
cp "$WP_BASE/wp-config.php" "$BACKUP_DIR"
|
||||
echo OK
|
||||
|
||||
echo "successful backup in $BACKUP_DIR, db + wp-content + wp-config"
|
||||
@@ -0,0 +1,37 @@
|
||||
server {
|
||||
listen {{ env.APP_PORT }} default_server;
|
||||
|
||||
access_log /var/log/nginx/{{ env.APP_NAME }}/wp-access.log;
|
||||
error_log /var/log/nginx/{{ env.APP_NAME }}/wp-error.log;
|
||||
|
||||
client_max_body_size 50M;
|
||||
root /var/www/wordpress/{{ env.APP_NAME }};
|
||||
index index.php index.html index.htm;
|
||||
charset UTF-8;
|
||||
|
||||
location / {
|
||||
try_files $uri/ /index.php?$args;
|
||||
}
|
||||
|
||||
location ~ \.php$ {
|
||||
try_files $uri =404;
|
||||
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||
fastcgi_pass unix:/run/php/php-fpm.sock;
|
||||
fastcgi_index index.php;
|
||||
include fastcgi.conf;
|
||||
}
|
||||
|
||||
location ~* \.(js|css|png|jpg|jpeg|svg|gif|ico|eot|otf|ttf|woff|woff2|mp3|wav|ogg)$ {
|
||||
add_header Access-Control-Allow-Origin *;
|
||||
access_log off; log_not_found off; expires 30d;
|
||||
}
|
||||
|
||||
# Mailpoet - tinyMCE quick fix
|
||||
location ~ /wp-content/plugins/wysija-newsletters/js/tinymce/.*\.(htm|html)$ {
|
||||
add_header Access-Control-Allow-Origin *;
|
||||
access_log off; log_not_found off; expires 30d;
|
||||
}
|
||||
|
||||
location = /robots.txt { access_log off; log_not_found off; }
|
||||
location ~ /\. { deny all; access_log off; log_not_found off; }
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
#!/bin/bash
|
||||
|
||||
### error_handling
|
||||
|
||||
function trap_error() {
|
||||
error_code=$1
|
||||
error_line=$2
|
||||
|
||||
if [[ ${error_code} -lt 100 ]]; then
|
||||
printf "\nEXIT #${error_code} due to error at line ${error_line} : \n-----------------------------------------\n"
|
||||
sed "${error_line}q;d" $0
|
||||
echo
|
||||
fi
|
||||
exit $error_code
|
||||
}
|
||||
set -e
|
||||
trap 'trap_error $? $LINENO' ERR
|
||||
|
||||
### ------------------
|
||||
|
||||
function detectWordpress() {
|
||||
local result=$(pwd)
|
||||
while [[ ! ("$result" == / || -f "$result/wp-config.php") ]]; do
|
||||
result=$(dirname "$result")
|
||||
done
|
||||
|
||||
if [[ "$result" == / ]]; then
|
||||
echo >&2 "no WORDPRESS detected!"
|
||||
exit 100
|
||||
fi
|
||||
|
||||
echo "$result"
|
||||
}
|
||||
|
||||
function getConfigComment() {
|
||||
local result=$(grep -e "^#" $WP_CONFIG | grep "$1" | head -n1 | cut -d ',' -f2 | cut -d \' -f2)
|
||||
if [[ -z "$result" ]]; then
|
||||
echo "config comment: $1 not found!"
|
||||
exit 2
|
||||
fi
|
||||
echo "$result"
|
||||
}
|
||||
function getConfigEntry() {
|
||||
local result=$(grep "$1" $WP_CONFIG | head -n1 | cut -d ',' -f2 | cut -d \' -f2)
|
||||
if [[ -z "$result" ]]; then
|
||||
echo "config entry: $1 not found!"
|
||||
exit 2
|
||||
fi
|
||||
echo "$result"
|
||||
}
|
||||
|
||||
function sql() {
|
||||
local result=$(echo "$1" | mysql -srN -u $DB_USER -h $DB_HOST $DB_NAME -p$DB_PASS 2>&1)
|
||||
if [[ $result =~ ^ERROR ]]; then
|
||||
echo >&2 "sql failure: $result"
|
||||
exit 3
|
||||
else
|
||||
echo "$result"
|
||||
fi
|
||||
}
|
||||
|
||||
function sqlFile() {
|
||||
local result=$(cat "$1" | mysql -srN -u $DB_USER -h $DB_HOST $DB_NAME -p$DB_PASS 2>&1)
|
||||
if [[ $result =~ ^ERROR ]]; then
|
||||
echo >&2 "sql failure: $result"
|
||||
exit 3
|
||||
else
|
||||
echo "$result"
|
||||
fi
|
||||
}
|
||||
function changeHome() {
|
||||
local FROM=$1
|
||||
local TO=$2
|
||||
sql "UPDATE wp_options SET option_value = replace(option_value, '$FROM', '$TO') WHERE option_name = 'home' OR option_name = 'siteurl'"
|
||||
sql "UPDATE wp_posts SET guid = replace(guid, '$FROM','$TO')"
|
||||
sql "UPDATE wp_posts SET post_content = replace(post_content, '$FROM', '$TO')"
|
||||
sql "UPDATE wp_postmeta SET meta_value = replace(meta_value,'$FROM','$TO')"
|
||||
}
|
||||
|
||||
function lastMigration() {
|
||||
sql "SELECT migration_file FROM migrations ORDER BY last_run DESC LIMIT 1"
|
||||
}
|
||||
|
||||
function upgradeMigration() {
|
||||
local LAST_MIGRATION=$1
|
||||
local UPGRADE=false
|
||||
if [[ "$LAST_MIGRATION" == '' ]]; then
|
||||
UPGRADE=true
|
||||
fi
|
||||
|
||||
local MIG_BASE="$WP_BASE/wp-content/migrations"
|
||||
local MIGRATIONS=$(ls -p1 $MIG_BASE | grep -v /)
|
||||
local MIG_FILE
|
||||
for mig in $MIGRATIONS; do
|
||||
if [[ "$UPGRADE" == true ]]; then
|
||||
printf "applying %50s ... " $mig
|
||||
printf "%d %d" $(sqlFile $MIG_BASE/$mig)
|
||||
echo " DONE"
|
||||
MIG_FILE=$mig
|
||||
else
|
||||
printf "useless %50s \n" $mig
|
||||
if [[ "$LAST_MIGRATION" == "$mig" ]]; then
|
||||
UPGRADE=true
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ $UPGRADE == true && $MIG_FILE != '' ]]; then
|
||||
local done=$(sql "INSERT INTO migrations(migration_file, last_run) VALUES ('$mig', NOW())")
|
||||
echo "all migrations succeeded, wrote: $mig"
|
||||
else
|
||||
echo "already up-to-date"
|
||||
fi
|
||||
}
|
||||
|
||||
function buildMigrations() {
|
||||
if [[ ! -d "$WP_BASE"/wp-content/migrations ]]; then
|
||||
mkdir -p "$WP_BASE"/wp-content/migrations
|
||||
echo "migrations folder created!"
|
||||
fi
|
||||
|
||||
sql "CREATE TABLE IF NOT EXISTS migrations (id int(11) NOT NULL AUTO_INCREMENT, migration_file varchar(255) COLLATE utf8_unicode_ci NOT NULL, last_run varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (id) )"
|
||||
|
||||
}
|
||||
|
||||
function playEnvironment() {
|
||||
|
||||
buildMigrations
|
||||
|
||||
local PLATFORM=$1
|
||||
local PLATFORM_BASE="$WP_BASE/wp-content/migrations/$PLATFORM"
|
||||
if [[ -d "$PLATFORM_BASE" ]]; then
|
||||
echo play platform $PLATFORM
|
||||
|
||||
local MIGRATIONS=$(ls -p1 $PLATFORM_BASE | grep -v /)
|
||||
for mig in $MIGRATIONS; do
|
||||
printf "applying %50s ... " $mig
|
||||
printf "%d %d" $(sqlFile $PLATFORM_BASE/$mig)
|
||||
echo " DONE"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
## MAIN
|
||||
## ----
|
||||
|
||||
WP_BASE=$(detectWordpress)
|
||||
WP_CONFIG="$WP_BASE/wp-config.php"
|
||||
echo "WP_BASE = $WP_BASE"
|
||||
|
||||
WP_HOME=$(getConfigComment WP_HOME)
|
||||
echo "WP_HOME = $WP_HOME"
|
||||
|
||||
DB_HOST=$(getConfigEntry DB_HOST)
|
||||
DB_NAME=$(getConfigEntry DB_NAME)
|
||||
DB_USER=$(getConfigEntry DB_USER)
|
||||
DB_PASS=$(getConfigEntry DB_PASSWORD)
|
||||
|
||||
CURRENT_HOME=$(sql "SELECT option_value FROM wp_options WHERE option_name = 'home'")
|
||||
if [[ "$CURRENT_HOME" != "$WP_HOME" ]]; then
|
||||
echo "HOME detected = $CURRENT_HOME , needs to apply changes"
|
||||
$(changeHome "$CURRENT_HOME" "$WP_HOME")
|
||||
fi
|
||||
|
||||
if [[ "$WP_HOME" =~ https?:\/\/beta[0-9]*\..*|https?:\/\/.*\.beta[0-9]*\..* ]]; then
|
||||
playEnvironment BETA
|
||||
else
|
||||
if [[ "$WP_HOME" =~ https?:\/\/dev[0-9]*\..*|https?:\/\/.*\.dev[0-9]*\..* ]]; then
|
||||
playEnvironment DEV
|
||||
else
|
||||
playEnvironment PROD
|
||||
fi
|
||||
fi
|
||||
|
||||
CURRENT_MIGRATION=$(lastMigration)
|
||||
upgradeMigration "$CURRENT_MIGRATION"
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ -x /usr/sbin/autopostgresqlbackup ]; then
|
||||
/usr/sbin/autopostgresqlbackup
|
||||
fi
|
||||
@@ -0,0 +1,122 @@
|
||||
# ===============================
|
||||
# === Debian specific options ===
|
||||
#================================
|
||||
|
||||
# By default, on Debian systems, only 'postgres' user
|
||||
# is allowed to access PostgreSQL databases without password.
|
||||
# In order to dump databases we need to run pg_dump/psql
|
||||
# commands as 'postgres' with su.
|
||||
#
|
||||
# The following setting has been added to workraound this issue.
|
||||
# (if it is set to empty, 'su' usage will be disabled)
|
||||
SU_USERNAME=postgres
|
||||
|
||||
#=====================================================================
|
||||
# Set the following variables to your system needs
|
||||
# (Detailed instructions below variables)
|
||||
#=====================================================================
|
||||
|
||||
# Username to access the PostgreSQL server e.g. dbuser
|
||||
USERNAME=postgres
|
||||
|
||||
# Password
|
||||
# create a file $HOME/.pgpass containing a line like this
|
||||
# hostname:*:*:dbuser:dbpass
|
||||
# replace hostname with the value of DBHOST and postgres with
|
||||
# the value of USERNAME
|
||||
|
||||
# Host name (or IP address) of PostgreSQL server e.g localhost
|
||||
DBHOST=localhost
|
||||
|
||||
# List of DBNAMES for Daily/Weekly Backup e.g. "DB1 DB2 DB3"
|
||||
DBNAMES="all"
|
||||
|
||||
# pseudo database name used to dump global objects (users, roles, tablespaces)
|
||||
GLOBALS_OBJECTS="postgres_globals"
|
||||
|
||||
# Backup directory location e.g /backups
|
||||
BACKUPDIR="/mnt/BACKUP/postgresql"
|
||||
|
||||
# Mail setup
|
||||
# What would you like to be mailed to you?
|
||||
# - log : send only log file
|
||||
# - files : send log file and sql files as attachments (see docs)
|
||||
# - stdout : will simply output the log to the screen if run manually.
|
||||
# - quiet : Only send logs if an error occurs to the MAILADDR.
|
||||
MAILCONTENT="quiet"
|
||||
|
||||
# Set the maximum allowed email size in k. (4000 = approx 5MB email [see docs])
|
||||
MAXATTSIZE="4000"
|
||||
|
||||
# Email Address to send mail to? (user@domain.com)
|
||||
MAILADDR="root"
|
||||
|
||||
# ============================================================
|
||||
# === ADVANCED OPTIONS ( Read the doc's below for details )===
|
||||
#=============================================================
|
||||
|
||||
# List of DBBNAMES for Monthly Backups.
|
||||
MDBNAMES="$DBNAMES"
|
||||
GLOBALS_OBJECTS_INCLUDE="no"
|
||||
# List of DBNAMES to EXLUCDE if DBNAMES are set to all (must be in " quotes)
|
||||
DBEXCLUDE="postgres template1"
|
||||
|
||||
# Include CREATE DATABASE in backup?
|
||||
CREATE_DATABASE=yes
|
||||
|
||||
# Separate backup directory and file for each DB? (yes or no)
|
||||
SEPDIR=yes
|
||||
|
||||
# Which day do you want weekly backups? (1 to 7 where 1 is Monday)
|
||||
DOWEEKLY=6
|
||||
|
||||
# Choose Compression type. (gzip, bzip2 or xz)
|
||||
COMP=gzip
|
||||
|
||||
# Compress communications between backup server and PostgreSQL server?
|
||||
# set compression level from 0 to 9 (0 means no compression)
|
||||
COMMCOMP=0
|
||||
|
||||
# Additionally keep a copy of the most recent backup in a seperate directory.
|
||||
LATEST=no
|
||||
|
||||
# OPT string for use with pg_dump ( see man pg_dump )
|
||||
OPT=""
|
||||
|
||||
# Backup files extension
|
||||
EXT="sql"
|
||||
|
||||
# Backup files permissions
|
||||
PERM=600
|
||||
|
||||
# Encyrption settings
|
||||
# (inspired by http://blog.altudov.com/2010/09/27/using-openssl-for-asymmetric-encryption-of-backups/)
|
||||
#
|
||||
# Once the backup done, each SQL dump will be encrypted and the original file
|
||||
# will be deleted (if encryption was successful).
|
||||
# It is recommended to backup into a staging directory, and then use the
|
||||
# POSTBACKUP script to sync the encrypted files to the desired location.
|
||||
#
|
||||
# Encryption uses private/public keys. You can generate the key pairs like the following:
|
||||
# openssl req -x509 -nodes -days 100000 -newkey rsa:2048 -keyout backup.key -out backup.crt -subj '/'
|
||||
#
|
||||
# Decryption:
|
||||
# openssl smime -decrypt -in backup.sql.gz.enc -binary -inform DEM -inkey backup.key -out backup.sql.gz
|
||||
|
||||
# Enable encryption
|
||||
ENCRYPTION=no
|
||||
|
||||
# Encryption public key
|
||||
ENCRYPTION_PUBLIC_KEY="/etc/ssl/certs/autopostgresqlbackup.crt"
|
||||
|
||||
# Encryption Cipher (see enc manpage)
|
||||
ENCRYPTION_CIPHER="aes256"
|
||||
|
||||
# Suffix for encyrpted files
|
||||
ENCRYPTION_SUFFIX=".enc"
|
||||
|
||||
# Command to run before backups (uncomment to use)
|
||||
#PREBACKUP="/etc/postgresql-backup-pre"
|
||||
|
||||
# Command run after backups (uncomment to use)
|
||||
#POSTBACKUP="/etc/postgresql-backup-post"
|
||||
Executable
+666
@@ -0,0 +1,666 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# PostgreSQL Backup Script Ver 1.0
|
||||
# http://autopgsqlbackup.frozenpc.net
|
||||
# Copyright (c) 2005 Aaron Axelsen <axelseaa@amadmax.com>
|
||||
# 2005 Friedrich Lobenstock <fl@fl.priv.at>
|
||||
# 2013-2019 Emmanuel Bouthenot <kolter@openics.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
#=====================================================================
|
||||
# Set the following variables to your system needs
|
||||
# (Detailed instructions below variables)
|
||||
#=====================================================================
|
||||
|
||||
# Username to access the PostgreSQL server e.g. dbuser
|
||||
USERNAME=postgres
|
||||
|
||||
# Password
|
||||
# create a file $HOME/.pgpass containing a line like this
|
||||
# hostname:*:*:dbuser:dbpass
|
||||
# replace hostname with the value of DBHOST and postgres with
|
||||
# the value of USERNAME
|
||||
|
||||
# Host name (or IP address) of PostgreSQL server e.g localhost
|
||||
DBHOST=localhost
|
||||
|
||||
# List of DBNAMES for Daily/Weekly Backup e.g. "DB1 DB2 DB3"
|
||||
DBNAMES="all"
|
||||
|
||||
# pseudo database name used to dump global objects (users, roles, tablespaces)
|
||||
GLOBALS_OBJECTS="postgres_globals"
|
||||
|
||||
# Backup directory location e.g /backups
|
||||
BACKUPDIR="/backups"
|
||||
GLOBALS_OBJECTS_INCLUDE="yes"
|
||||
|
||||
# Mail setup
|
||||
# What would you like to be mailed to you?
|
||||
# - log : send only log file
|
||||
# - files : send log file and sql files as attachments (see docs)
|
||||
# - stdout : will simply output the log to the screen if run manually.
|
||||
# - quiet : Only send logs if an error occurs to the MAILADDR.
|
||||
MAILCONTENT="stdout"
|
||||
|
||||
# Set the maximum allowed email size in k. (4000 = approx 5MB email [see docs])
|
||||
MAXATTSIZE="4000"
|
||||
|
||||
# Email Address to send mail to? (user@domain.com)
|
||||
MAILADDR="user@domain.com"
|
||||
|
||||
# ============================================================
|
||||
# === ADVANCED OPTIONS ( Read the doc's below for details )===
|
||||
#=============================================================
|
||||
|
||||
# List of DBBNAMES for Monthly Backups.
|
||||
MDBNAMES="template1 $DBNAMES"
|
||||
|
||||
# List of DBNAMES to EXLUCDE if DBNAMES are set to all (must be in " quotes)
|
||||
DBEXCLUDE=""
|
||||
|
||||
# Include CREATE DATABASE in backup?
|
||||
CREATE_DATABASE=yes
|
||||
|
||||
# Separate backup directory and file for each DB? (yes or no)
|
||||
SEPDIR=yes
|
||||
|
||||
# Which day do you want weekly backups? (1 to 7 where 1 is Monday)
|
||||
DOWEEKLY=6
|
||||
|
||||
# Choose Compression type. (gzip, bzip2 or xz)
|
||||
COMP=gzip
|
||||
|
||||
# Compress communications between backup server and PostgreSQL server?
|
||||
# set compression level from 0 to 9 (0 means no compression)
|
||||
COMMCOMP=0
|
||||
|
||||
# Additionally keep a copy of the most recent backup in a seperate directory.
|
||||
LATEST=no
|
||||
|
||||
# OPT string for use with pg_dump ( see man pg_dump )
|
||||
OPT=""
|
||||
|
||||
# Backup files extension
|
||||
EXT="sql"
|
||||
|
||||
# Backup files permissions
|
||||
PERM=600
|
||||
|
||||
# Encyrption settings
|
||||
# (inspired by http://blog.altudov.com/2010/09/27/using-openssl-for-asymmetric-encryption-of-backups/)
|
||||
#
|
||||
# Once the backup done, each SQL dump will be encrypted and the original file
|
||||
# will be deleted (if encryption was successful).
|
||||
# It is recommended to backup into a staging directory, and then use the
|
||||
# POSTBACKUP script to sync the encrypted files to the desired location.
|
||||
#
|
||||
# Encryption uses private/public keys. You can generate the key pairs like the following:
|
||||
# openssl req -x509 -nodes -days 100000 -newkey rsa:2048 -keyout backup.key -out backup.crt -subj '/'
|
||||
#
|
||||
# Decryption:
|
||||
# openssl smime -decrypt -in backup.sql.gz.enc -binary -inform DEM -inkey backup.key -out backup.sql.gz
|
||||
|
||||
# Enable encryption
|
||||
ENCRYPTION=no
|
||||
|
||||
# Encryption public key
|
||||
ENCRYPTION_PUBLIC_KEY=""
|
||||
|
||||
# Encryption Cipher (see enc manpage)
|
||||
ENCRYPTION_CIPHER="aes256"
|
||||
|
||||
# Suffix for encyrpted files
|
||||
ENCRYPTION_SUFFIX=".enc"
|
||||
|
||||
# Command to run before backups (uncomment to use)
|
||||
#PREBACKUP="/etc/postgresql-backup-pre"
|
||||
|
||||
# Command run after backups (uncomment to use)
|
||||
#POSTBACKUP="/etc/postgresql-backup-post"
|
||||
|
||||
#=====================================================================
|
||||
# Debian specific options ===
|
||||
#=====================================================================
|
||||
|
||||
if [ -f /etc/default/autopostgresqlbackup ]; then
|
||||
. /etc/default/autopostgresqlbackup
|
||||
fi
|
||||
|
||||
#=====================================================================
|
||||
# Options documentation
|
||||
#=====================================================================
|
||||
# Set USERNAME and PASSWORD of a user that has at least SELECT permission
|
||||
# to ALL databases.
|
||||
#
|
||||
# Set the DBHOST option to the server you wish to backup, leave the
|
||||
# default to backup "this server".(to backup multiple servers make
|
||||
# copies of this file and set the options for that server)
|
||||
#
|
||||
# Put in the list of DBNAMES(Databases)to be backed up. If you would like
|
||||
# to backup ALL DBs on the server set DBNAMES="all".(if set to "all" then
|
||||
# any new DBs will automatically be backed up without needing to modify
|
||||
# this backup script when a new DB is created).
|
||||
#
|
||||
# If the DB you want to backup has a space in the name replace the space
|
||||
# with a % e.g. "data base" will become "data%base"
|
||||
# NOTE: Spaces in DB names may not work correctly when SEPDIR=no.
|
||||
#
|
||||
# You can change the backup storage location from /backups to anything
|
||||
# you like by using the BACKUPDIR setting..
|
||||
#
|
||||
# The MAILCONTENT and MAILADDR options and pretty self explanitory, use
|
||||
# these to have the backup log mailed to you at any email address or multiple
|
||||
# email addresses in a space seperated list.
|
||||
# (If you set mail content to "log" you will require access to the "mail" program
|
||||
# on your server. If you set this to "files" you will have to have mutt installed
|
||||
# on your server. If you set it to "stdout" it will log to the screen if run from
|
||||
# the console or to the cron job owner if run through cron. If you set it to "quiet"
|
||||
# logs will only be mailed if there are errors reported. )
|
||||
#
|
||||
# MAXATTSIZE sets the largest allowed email attachments total (all backup files) you
|
||||
# want the script to send. This is the size before it is encoded to be sent as an email
|
||||
# so if your mail server will allow a maximum mail size of 5MB I would suggest setting
|
||||
# MAXATTSIZE to be 25% smaller than that so a setting of 4000 would probably be fine.
|
||||
#
|
||||
# Finally copy autopostgresqlbackup.sh to anywhere on your server and make sure
|
||||
# to set executable permission. You can also copy the script to
|
||||
# /etc/cron.daily to have it execute automatically every night or simply
|
||||
# place a symlink in /etc/cron.daily to the file if you wish to keep it
|
||||
# somwhere else.
|
||||
# NOTE:On Debian copy the file with no extention for it to be run
|
||||
# by cron e.g just name the file "autopostgresqlbackup"
|
||||
#
|
||||
# Thats it..
|
||||
#
|
||||
#
|
||||
# === Advanced options doc's ===
|
||||
#
|
||||
# The list of MDBNAMES is the DB's to be backed up only monthly. You should
|
||||
# always include "template1" in this list to backup the default database
|
||||
# template used to create new databases.
|
||||
# NOTE: If DBNAMES="all" then MDBNAMES has no effect as all DBs will be backed
|
||||
# up anyway.
|
||||
#
|
||||
# If you set DBNAMES="all" you can configure the option DBEXCLUDE. Other
|
||||
# wise this option will not be used.
|
||||
# This option can be used if you want to backup all dbs, but you want
|
||||
# exclude some of them. (eg. a db is to big).
|
||||
#
|
||||
# Set CREATE_DATABASE to "yes" (the default) if you want your SQL-Dump to create
|
||||
# a database with the same name as the original database when restoring.
|
||||
# Saying "no" here will allow your to specify the database name you want to
|
||||
# restore your dump into, making a copy of the database by using the dump
|
||||
# created with autopostgresqlbackup.
|
||||
# NOTE: Not used if SEPDIR=no
|
||||
#
|
||||
# The SEPDIR option allows you to choose to have all DBs backed up to
|
||||
# a single file (fast restore of entire server in case of crash) or to
|
||||
# seperate directories for each DB (each DB can be restored seperately
|
||||
# in case of single DB corruption or loss).
|
||||
#
|
||||
# To set the day of the week that you would like the weekly backup to happen
|
||||
# set the DOWEEKLY setting, this can be a value from 1 to 7 where 1 is Monday,
|
||||
# The default is 6 which means that weekly backups are done on a Saturday.
|
||||
#
|
||||
# COMP is used to choose the copmression used, options are gzip or bzip2.
|
||||
# bzip2 will produce slightly smaller files but is more processor intensive so
|
||||
# may take longer to complete.
|
||||
#
|
||||
# COMMCOMP is used to set the compression level (from 0 to 9, 0 means no compression)
|
||||
# between the client and the server, so it is useful to save bandwidth when backing up
|
||||
# a remote PostgresSQL server over the network.
|
||||
#
|
||||
# LATEST is to store an additional copy of the latest backup to a standard
|
||||
# location so it can be downloaded bt thrid party scripts.
|
||||
#
|
||||
# Use PREBACKUP and POSTBACKUP to specify Per and Post backup commands
|
||||
# or scripts to perform tasks either before or after the backup process.
|
||||
#
|
||||
#
|
||||
#=====================================================================
|
||||
# Backup Rotation..
|
||||
#=====================================================================
|
||||
#
|
||||
# Daily Backups are rotated weekly..
|
||||
# Weekly Backups are run by default on Saturday Morning when
|
||||
# cron.daily scripts are run...Can be changed with DOWEEKLY setting..
|
||||
# Weekly Backups are rotated on a 5 week cycle..
|
||||
# Monthly Backups are run on the 1st of the month..
|
||||
# Monthly Backups are NOT rotated automatically...
|
||||
# It may be a good idea to copy Monthly backups offline or to another
|
||||
# server..
|
||||
#
|
||||
#=====================================================================
|
||||
# Please Note!!
|
||||
#=====================================================================
|
||||
#
|
||||
# I take no resposibility for any data loss or corruption when using
|
||||
# this script..
|
||||
# This script will not help in the event of a hard drive crash. If a
|
||||
# copy of the backup has not be stored offline or on another PC..
|
||||
# You should copy your backups offline regularly for best protection.
|
||||
#
|
||||
# Happy backing up...
|
||||
#
|
||||
#=====================================================================
|
||||
# Restoring
|
||||
#=====================================================================
|
||||
# Firstly you will need to uncompress the backup file.
|
||||
# eg.
|
||||
# gunzip file.gz (or bunzip2 file.bz2)
|
||||
#
|
||||
# Next you will need to use the postgresql client to restore the DB from the
|
||||
# sql file.
|
||||
# eg.
|
||||
# psql --host dbserver --dbname database < /path/file.sql
|
||||
#
|
||||
# NOTE: Make sure you use "<" and not ">" in the above command because
|
||||
# you are piping the file.sql to psql and not the other way around.
|
||||
#
|
||||
# Lets hope you never have to use this.. :)
|
||||
#
|
||||
#=====================================================================
|
||||
# Change Log
|
||||
#=====================================================================
|
||||
#
|
||||
# VER 1.0 - (2005-03-25)
|
||||
# Initial Release - based on AutoMySQLBackup 2.2
|
||||
#
|
||||
#=====================================================================
|
||||
#=====================================================================
|
||||
#=====================================================================
|
||||
#
|
||||
# Should not need to be modified from here down!!
|
||||
#
|
||||
#=====================================================================
|
||||
#=====================================================================
|
||||
#=====================================================================
|
||||
PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/postgres/bin:/usr/local/pgsql/bin
|
||||
DATE=$(date +%Y-%m-%d_%Hh%Mm) # Datestamp e.g 2002-09-21
|
||||
DOW=$(date +%A) # Day of the week e.g. Monday
|
||||
DNOW=$(date +%u) # Day number of the week 1 to 7 where 1 represents Monday
|
||||
DOM=$(date +%d) # Date of the Month e.g. 27
|
||||
M=$(date +%B) # Month e.g January
|
||||
W=$(date +%V) # Week Number e.g 37
|
||||
VER=1.0 # Version Number
|
||||
LOGFILE=$BACKUPDIR/${DBHOST//\//_}-$(date +%N).log # Logfile Name
|
||||
LOGERR=$BACKUPDIR/ERRORS_${DBHOST//\//_}-$(date +%N).log # Logfile Name
|
||||
BACKUPFILES=""
|
||||
|
||||
# Add --compress pg_dump option to $OPT
|
||||
if [ "$COMMCOMP" -gt 0 ]; then
|
||||
OPT="$OPT --compress=$COMMCOMP"
|
||||
fi
|
||||
|
||||
# Create required directories
|
||||
if [ ! -e "$BACKUPDIR" ]; then # Check Backup Directory exists.
|
||||
mkdir -p "$BACKUPDIR"
|
||||
fi
|
||||
|
||||
if [ ! -e "$BACKUPDIR/daily" ]; then # Check Daily Directory exists.
|
||||
mkdir -p "$BACKUPDIR/daily"
|
||||
fi
|
||||
|
||||
if [ ! -e "$BACKUPDIR/weekly" ]; then # Check Weekly Directory exists.
|
||||
mkdir -p "$BACKUPDIR/weekly"
|
||||
fi
|
||||
|
||||
if [ ! -e "$BACKUPDIR/monthly" ]; then # Check Monthly Directory exists.
|
||||
mkdir -p "$BACKUPDIR/monthly"
|
||||
fi
|
||||
|
||||
if [ "$LATEST" = "yes" ]; then
|
||||
if [ ! -e "$BACKUPDIR/latest" ]; then # Check Latest Directory exists.
|
||||
mkdir -p "$BACKUPDIR/latest"
|
||||
fi
|
||||
rm -f "$BACKUPDIR"/latest/*
|
||||
fi
|
||||
|
||||
# IO redirection for logging.
|
||||
touch $LOGFILE
|
||||
exec 6>&1 # Link file descriptor #6 with stdout.
|
||||
# Saves stdout.
|
||||
exec >$LOGFILE # stdout replaced with file $LOGFILE.
|
||||
touch $LOGERR
|
||||
exec 7>&2 # Link file descriptor #7 with stderr.
|
||||
# Saves stderr.
|
||||
exec 2>$LOGERR # stderr replaced with file $LOGERR.
|
||||
|
||||
# Functions
|
||||
|
||||
# Database dump function
|
||||
dbdump() {
|
||||
rm -f $2
|
||||
touch $2
|
||||
chmod $PERM $2
|
||||
for db in $1; do
|
||||
if [ -n "$SU_USERNAME" ]; then
|
||||
if [ "$db" = "$GLOBALS_OBJECTS" ]; then
|
||||
su $SU_USERNAME -l -c "pg_dumpall $PGHOST --globals-only" >>$2
|
||||
else
|
||||
su $SU_USERNAME -l -c "pg_dump $PGHOST $OPT $db" >>$2
|
||||
fi
|
||||
else
|
||||
if [ "$db" = "$GLOBALS_OBJECTS" ]; then
|
||||
pg_dumpall --username=$USERNAME $PGHOST --globals-only >>$2
|
||||
else
|
||||
pg_dump --username=$USERNAME $PGHOST $OPT $db >>$2
|
||||
fi
|
||||
fi
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
# Encryption function
|
||||
encryption() {
|
||||
ENCRYPTED_FILE="$1$ENCRYPTION_SUFFIX"
|
||||
# Encrypt as needed
|
||||
if [ "$ENCRYPTION" = "yes" ]; then
|
||||
echo
|
||||
echo "Encrypting $1"
|
||||
echo " to $ENCRYPTED_FILE"
|
||||
echo " using cypher $ENCRYPTION_CIPHER and public key $ENCRYPTION_PUBLIC_KEY"
|
||||
if openssl smime -encrypt -$ENCRYPTION_CIPHER -binary -outform DEM \
|
||||
-out "$ENCRYPTED_FILE" \
|
||||
-in "$1" "$ENCRYPTION_PUBLIC_KEY"; then
|
||||
echo " and remove $1"
|
||||
chmod $PERM "$ENCRYPTED_FILE"
|
||||
rm -f "$1"
|
||||
fi
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# Compression (and encrypt) function plus latest copy
|
||||
SUFFIX=""
|
||||
compression() {
|
||||
if [ "$COMP" = "gzip" ]; then
|
||||
gzip -f "$1"
|
||||
echo
|
||||
echo Backup Information for "$1"
|
||||
gzip -l "$1.gz"
|
||||
SUFFIX=".gz"
|
||||
elif [ "$COMP" = "bzip2" ]; then
|
||||
echo Compression information for "$1.bz2"
|
||||
bzip2 -f -v $1 2>&1
|
||||
SUFFIX=".bz2"
|
||||
elif [ "$COMP" = "xz" ]; then
|
||||
echo Compression information for "$1.xz"
|
||||
xz -9 -v $1 2>&1
|
||||
SUFFIX=".xz"
|
||||
else
|
||||
echo "No compression option set, check advanced settings"
|
||||
fi
|
||||
encryption $1$SUFFIX
|
||||
if [ "$LATEST" = "yes" ]; then
|
||||
cp $1$SUFFIX* "$BACKUPDIR/latest/"
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# Run command before we begin
|
||||
if [ "$PREBACKUP" ]; then
|
||||
echo ======================================================================
|
||||
echo "Prebackup command output."
|
||||
echo
|
||||
$PREBACKUP
|
||||
echo
|
||||
echo ======================================================================
|
||||
echo
|
||||
fi
|
||||
|
||||
if [ "$SEPDIR" = "yes" ]; then # Check if CREATE DATABSE should be included in Dump
|
||||
if [ "$CREATE_DATABASE" = "no" ]; then
|
||||
OPT="$OPT"
|
||||
else
|
||||
OPT="$OPT --create"
|
||||
fi
|
||||
else
|
||||
OPT="$OPT"
|
||||
fi
|
||||
|
||||
# Hostname for LOG information
|
||||
if [ "$DBHOST" = "localhost" ]; then
|
||||
HOST=$(hostname)
|
||||
PGHOST=""
|
||||
else
|
||||
HOST=$DBHOST
|
||||
PGHOST="-h $DBHOST"
|
||||
fi
|
||||
|
||||
# If backing up all DBs on the server
|
||||
if [ "$DBNAMES" = "all" ]; then
|
||||
if [ -n "$SU_USERNAME" ]; then
|
||||
DBNAMES="$(su $SU_USERNAME -l -c "LANG=C psql -U $USERNAME $PGHOST -l -A -F: | sed -ne '/:/ { /Name:Owner/d; /template0/d; s/:.*$//; p }'")"
|
||||
else
|
||||
DBNAMES="$(LANG=C psql -U $USERNAME $PGHOST -l -A -F: | sed -ne "/:/ { /Name:Owner/d; /template0/d; s/:.*$//; p }")"
|
||||
fi
|
||||
|
||||
# If DBs are excluded
|
||||
for exclude in $DBEXCLUDE; do
|
||||
DBNAMES=$(echo $DBNAMES | sed "s/\b$exclude\b//g")
|
||||
done
|
||||
DBNAMES="$(echo $DBNAMES | tr '\n' ' ')"
|
||||
MDBNAMES=$DBNAMES
|
||||
fi
|
||||
|
||||
# Include global objects (users, tablespaces)
|
||||
if [ "$GLOBALS_OBJECTS_INCLUDE" = "yes" ]; then
|
||||
DBNAMES="$GLOBALS_OBJECTS $DBNAMES"
|
||||
MDBNAMES="$GLOBALS_OBJECTS $MDBNAMES"
|
||||
fi
|
||||
|
||||
echo ======================================================================
|
||||
echo AutoPostgreSQLBackup VER $VER
|
||||
echo http://autopgsqlbackup.frozenpc.net/
|
||||
echo
|
||||
echo Backup of Database Server - $HOST
|
||||
echo ======================================================================
|
||||
|
||||
# Test is seperate DB backups are required
|
||||
if [ "$SEPDIR" = "yes" ]; then
|
||||
echo Backup Start Time $(date)
|
||||
echo ======================================================================
|
||||
# Monthly Full Backup of all Databases
|
||||
if [ "$DOM" = "01" ]; then
|
||||
for MDB in $MDBNAMES; do
|
||||
|
||||
# Prepare $DB for using
|
||||
MDB="$(echo $MDB | sed 's/%/ /g')"
|
||||
|
||||
if [ ! -e "$BACKUPDIR/monthly/$MDB" ]; then # Check Monthly DB Directory exists.
|
||||
mkdir -p "$BACKUPDIR/monthly/$MDB"
|
||||
fi
|
||||
echo Monthly Backup of $MDB...
|
||||
dbdump "$MDB" "$BACKUPDIR/monthly/$MDB/${MDB}_$DATE.$M.$MDB.$EXT"
|
||||
compression "$BACKUPDIR/monthly/$MDB/${MDB}_$DATE.$M.$MDB.$EXT"
|
||||
BACKUPFILES="$BACKUPFILES $BACKUPDIR/monthly/$MDB/${MDB}_$DATE.$M.$MDB.$EXT$SUFFIX*"
|
||||
echo ----------------------------------------------------------------------
|
||||
done
|
||||
fi
|
||||
|
||||
for DB in $DBNAMES; do
|
||||
# Prepare $DB for using
|
||||
DB="$(echo $DB | sed 's/%/ /g')"
|
||||
|
||||
# Create Seperate directory for each DB
|
||||
if [ ! -e "$BACKUPDIR/daily/$DB" ]; then # Check Daily DB Directory exists.
|
||||
mkdir -p "$BACKUPDIR/daily/$DB"
|
||||
fi
|
||||
|
||||
if [ ! -e "$BACKUPDIR/weekly/$DB" ]; then # Check Weekly DB Directory exists.
|
||||
mkdir -p "$BACKUPDIR/weekly/$DB"
|
||||
fi
|
||||
|
||||
# Weekly Backup
|
||||
if [ "$DNOW" = "$DOWEEKLY" ]; then
|
||||
echo Weekly Backup of Database \( $DB \)
|
||||
echo Rotating 5 weeks Backups...
|
||||
if [ "$W" -le 05 ]; then
|
||||
REMW=$(expr 48 + $W)
|
||||
elif [ "$W" -lt 15 ]; then
|
||||
REMW=0$(expr $W - 5)
|
||||
else
|
||||
REMW=$(expr $W - 5)
|
||||
fi
|
||||
rm -fv "$BACKUPDIR/weekly/$DB/${DB}_week.$REMW".*
|
||||
echo
|
||||
dbdump "$DB" "$BACKUPDIR/weekly/$DB/${DB}_week.$W.$DATE.$EXT"
|
||||
compression "$BACKUPDIR/weekly/$DB/${DB}_week.$W.$DATE.$EXT"
|
||||
BACKUPFILES="$BACKUPFILES $BACKUPDIR/weekly/$DB/${DB}_week.$W.$DATE.$EXT$SUFFIX*"
|
||||
echo ----------------------------------------------------------------------
|
||||
|
||||
# Daily Backup
|
||||
else
|
||||
echo Daily Backup of Database \( $DB \)
|
||||
echo Rotating last weeks Backup...
|
||||
rm -fv "$BACKUPDIR/daily/$DB"/*."$DOW".$EXT*
|
||||
echo
|
||||
dbdump "$DB" "$BACKUPDIR/daily/$DB/${DB}_$DATE.$DOW.$EXT"
|
||||
compression "$BACKUPDIR/daily/$DB/${DB}_$DATE.$DOW.$EXT"
|
||||
BACKUPFILES="$BACKUPFILES $BACKUPDIR/daily/$DB/${DB}_$DATE.$DOW.$EXT$SUFFIX*"
|
||||
echo ----------------------------------------------------------------------
|
||||
fi
|
||||
done
|
||||
echo Backup End $(date)
|
||||
echo ======================================================================
|
||||
|
||||
else
|
||||
# One backup file for all DBs
|
||||
echo Backup Start $(date)
|
||||
echo ======================================================================
|
||||
# Monthly Full Backup of all Databases
|
||||
if [ "$DOM" = "01" ]; then
|
||||
echo Monthly full Backup of \( $MDBNAMES \)...
|
||||
dbdump "$MDBNAMES" "$BACKUPDIR/monthly/$DATE.$M.all-databases.$EXT"
|
||||
compression "$BACKUPDIR/monthly/$DATE.$M.all-databases.$EXT"
|
||||
BACKUPFILES="$BACKUPFILES $BACKUPDIR/monthly/$DATE.$M.all-databases.$EXT$SUFFIX*"
|
||||
echo ----------------------------------------------------------------------
|
||||
fi
|
||||
|
||||
# Weekly Backup
|
||||
if [ "$DNOW" = "$DOWEEKLY" ]; then
|
||||
echo Weekly Backup of Databases \( $DBNAMES \)
|
||||
echo
|
||||
echo Rotating 5 weeks Backups...
|
||||
if [ "$W" -le 05 ]; then
|
||||
REMW=$(expr 48 + $W)
|
||||
elif [ "$W" -lt 15 ]; then
|
||||
REMW=0$(expr $W - 5)
|
||||
else
|
||||
REMW=$(expr $W - 5)
|
||||
fi
|
||||
rm -fv "$BACKUPDIR/weekly/week.$REMW".*
|
||||
echo
|
||||
dbdump "$DBNAMES" "$BACKUPDIR/weekly/week.$W.$DATE.$EXT"
|
||||
compression "$BACKUPDIR/weekly/week.$W.$DATE.$EXT"
|
||||
BACKUPFILES="$BACKUPFILES $BACKUPDIR/weekly/week.$W.$DATE.$EXT$SUFFIX*"
|
||||
echo ----------------------------------------------------------------------
|
||||
# Daily Backup
|
||||
else
|
||||
echo Daily Backup of Databases \( $DBNAMES \)
|
||||
echo
|
||||
echo Rotating last weeks Backup...
|
||||
rm -fv "$BACKUPDIR"/daily/*."$DOW".$EXT*
|
||||
echo
|
||||
dbdump "$DBNAMES" "$BACKUPDIR/daily/$DATE.$DOW.$EXT"
|
||||
compression "$BACKUPDIR/daily/$DATE.$DOW.$EXT"
|
||||
BACKUPFILES="$BACKUPFILES $BACKUPDIR/daily/$DATE.$DOW.$EXT$SUFFIX*"
|
||||
echo ----------------------------------------------------------------------
|
||||
fi
|
||||
echo Backup End Time $(date)
|
||||
echo ======================================================================
|
||||
fi
|
||||
echo Total disk space used for backup storage..
|
||||
echo Size - Location
|
||||
echo $(du -hs "$BACKUPDIR")
|
||||
echo
|
||||
|
||||
# Run command when we're done
|
||||
if [ "$POSTBACKUP" ]; then
|
||||
echo ======================================================================
|
||||
echo "Postbackup command output."
|
||||
echo
|
||||
$POSTBACKUP
|
||||
echo
|
||||
echo ======================================================================
|
||||
fi
|
||||
|
||||
#Clean up IO redirection
|
||||
exec 1>&6 6>&- # Restore stdout and close file descriptor #6.
|
||||
exec 2>&7 7>&- # Restore stdout and close file descriptor #7.
|
||||
|
||||
if [ "$MAILCONTENT" = "files" ]; then
|
||||
if [ -s "$LOGERR" ]; then
|
||||
# Include error log if is larger than zero.
|
||||
BACKUPFILES="$BACKUPFILES $LOGERR"
|
||||
ERRORNOTE="WARNING: Error Reported - "
|
||||
fi
|
||||
#Get backup size
|
||||
ATTSIZE=$(du -c $BACKUPFILES | grep "[[:digit:][:space:]]total$" | sed s/\s*total//)
|
||||
if [ $MAXATTSIZE -ge $ATTSIZE ]; then
|
||||
if which biabam >/dev/null 2>&1; then
|
||||
BACKUPFILES=$(echo $BACKUPFILES | sed -r -e 's#\s+#,#g')
|
||||
biabam -s "PostgreSQL Backup Log and SQL Files for $HOST - $DATE" $BACKUPFILES $MAILADDR <$LOGFILE
|
||||
elif which heirloom-mailx >/dev/null 2>&1; then
|
||||
BACKUPFILES=$(echo $BACKUPFILES | sed -e 's# # -a #g')
|
||||
heirloom-mailx -s "PostgreSQL Backup Log and SQL Files for $HOST - $DATE" $BACKUPFILES $MAILADDR <$LOGFILE
|
||||
elif which neomutt >/dev/null 2>&1; then
|
||||
BACKUPFILES=$(echo $BACKUPFILES | sed -e 's# # -a #g')
|
||||
neomutt -s "PostgreSQL Backup Log and SQL Files for $HOST - $DATE" -a $BACKUPFILES -- $MAILADDR <$LOGFILE
|
||||
elif which mutt >/dev/null 2>&1; then
|
||||
BACKUPFILES=$(echo $BACKUPFILES | sed -e 's# # -a #g')
|
||||
mutt -s "PostgreSQL Backup Log and SQL Files for $HOST - $DATE" -a $BACKUPFILES -- $MAILADDR <$LOGFILE
|
||||
else
|
||||
cat "$LOGFILE" | mail -s "WARNING! - Enable to send PostgreSQL Backup dumps, no suitable mail client found on $HOST - $DATE" $MAILADDR
|
||||
fi
|
||||
else
|
||||
cat "$LOGFILE" | mail -s "WARNING! - PostgreSQL Backup exceeds set maximum attachment size on $HOST - $DATE" $MAILADDR
|
||||
fi
|
||||
elif [ "$MAILCONTENT" = "log" ]; then
|
||||
cat "$LOGFILE" | mail -s "PostgreSQL Backup Log for $HOST - $DATE" $MAILADDR
|
||||
if [ -s "$LOGERR" ]; then
|
||||
cat "$LOGERR" | mail -s "ERRORS REPORTED: PostgreSQL Backup error Log for $HOST - $DATE" $MAILADDR
|
||||
fi
|
||||
elif [ "$MAILCONTENT" = "quiet" ]; then
|
||||
if [ -s "$LOGERR" ]; then
|
||||
cat "$LOGERR" | mail -s "ERRORS REPORTED: PostgreSQL Backup error Log for $HOST - $DATE" $MAILADDR
|
||||
cat "$LOGFILE" | mail -s "PostgreSQL Backup Log for $HOST - $DATE" $MAILADDR
|
||||
fi
|
||||
else
|
||||
if [ -s "$LOGERR" ]; then
|
||||
cat "$LOGFILE"
|
||||
echo
|
||||
echo "###### WARNING ######"
|
||||
echo "Errors reported during AutoPostgreSQLBackup execution.. Backup failed"
|
||||
echo "Error log below.."
|
||||
cat "$LOGERR"
|
||||
else
|
||||
cat "$LOGFILE"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -s "$LOGERR" ]; then
|
||||
STATUS=1
|
||||
else
|
||||
STATUS=0
|
||||
fi
|
||||
|
||||
# Clean up Logfile
|
||||
rm -f "$LOGFILE"
|
||||
rm -f "$LOGERR"
|
||||
|
||||
exit $STATUS
|
||||
@@ -0,0 +1,162 @@
|
||||
[flags]
|
||||
# Whether to hide the average cpu entry.
|
||||
#hide_avg_cpu = false
|
||||
# Whether to use dot markers rather than braille.
|
||||
#dot_marker = false
|
||||
# The update rate of the application.
|
||||
#rate = 1000
|
||||
# Whether to put the CPU legend to the left.
|
||||
#left_legend = false
|
||||
# Whether to set CPU% on a process to be based on the total CPU or just current usage.
|
||||
#current_usage = false
|
||||
# Whether to group processes with the same name together by default.
|
||||
#group_processes = false
|
||||
# Whether to make process searching case sensitive by default.
|
||||
#case_sensitive = false
|
||||
# Whether to make process searching look for matching the entire word by default.
|
||||
#whole_word = false
|
||||
# Whether to make process searching use regex by default.
|
||||
#regex = false
|
||||
# Defaults to Celsius. Temperature is one of:
|
||||
#temperature_type = "k"
|
||||
#temperature_type = "f"
|
||||
#temperature_type = "c"
|
||||
#temperature_type = "kelvin"
|
||||
#temperature_type = "fahrenheit"
|
||||
#temperature_type = "celsius"
|
||||
# The default time interval (in milliseconds).
|
||||
#default_time_value = 60000
|
||||
# The time delta on each zoom in/out action (in milliseconds).
|
||||
#time_delta = 15000
|
||||
# Hides the time scale.
|
||||
#hide_time = false
|
||||
# Override layout default widget
|
||||
#default_widget_type = "proc"
|
||||
#default_widget_count = 1
|
||||
# Use basic mode
|
||||
#basic = false
|
||||
# Use the old network legend style
|
||||
#use_old_network_legend = false
|
||||
# Remove space in tables
|
||||
#hide_table_gap = false
|
||||
# Show the battery widgets
|
||||
#battery = false
|
||||
# Disable mouse clicks
|
||||
#disable_click = false
|
||||
# Built-in themes. Valid values are "default", "default-light", "gruvbox", "gruvbox-light", "nord", "nord-light"
|
||||
#color = "default"
|
||||
# Show memory values in the processes widget as values by default
|
||||
#mem_as_value = false
|
||||
# Show tree mode by default in the processes widget.
|
||||
#tree = false
|
||||
# Shows an indicator in table widgets tracking where in the list you are.
|
||||
#show_table_scroll_position = false
|
||||
# Show processes as their commands by default in the process widget.
|
||||
#process_command = false
|
||||
# Displays the network widget with binary prefixes.
|
||||
#network_use_binary_prefix = false
|
||||
# Displays the network widget using bytes.
|
||||
network_use_bytes = true
|
||||
# Displays the network widget with a log scale.
|
||||
#network_use_log = false
|
||||
# Hides advanced options to stop a process on Unix-like systems.
|
||||
#disable_advanced_kill = false
|
||||
|
||||
# These are all the components that support custom theming. Note that colour support
|
||||
# will depend on terminal support.
|
||||
|
||||
#[colors] # Uncomment if you want to use custom colors
|
||||
# Represents the colour of table headers (processes, CPU, disks, temperature).
|
||||
#table_header_color="LightBlue"
|
||||
# Represents the colour of the label each widget has.
|
||||
#widget_title_color="Gray"
|
||||
# Represents the average CPU color.
|
||||
#avg_cpu_color="Red"
|
||||
# Represents the colour the core will use in the CPU legend and graph.
|
||||
#cpu_core_colors=["LightMagenta", "LightYellow", "LightCyan", "LightGreen", "LightBlue", "LightRed", "Cyan", "Green", "Blue", "Red"]
|
||||
# Represents the colour RAM will use in the memory legend and graph.
|
||||
#ram_color="LightMagenta"
|
||||
# Represents the colour SWAP will use in the memory legend and graph.
|
||||
#swap_color="LightYellow"
|
||||
# Represents the colour rx will use in the network legend and graph.
|
||||
#rx_color="LightCyan"
|
||||
# Represents the colour tx will use in the network legend and graph.
|
||||
#tx_color="LightGreen"
|
||||
# Represents the colour of the border of unselected widgets.
|
||||
#border_color="Gray"
|
||||
# Represents the colour of the border of selected widgets.
|
||||
#highlighted_border_color="LightBlue"
|
||||
# Represents the colour of most text.
|
||||
#text_color="Gray"
|
||||
# Represents the colour of text that is selected.
|
||||
#selected_text_color="Black"
|
||||
# Represents the background colour of text that is selected.
|
||||
#selected_bg_color="LightBlue"
|
||||
# Represents the colour of the lines and text of the graph.
|
||||
#graph_color="Gray"
|
||||
# Represents the colours of the battery based on charge
|
||||
#high_battery_color="green"
|
||||
#medium_battery_color="yellow"
|
||||
#low_battery_color="red"
|
||||
|
||||
# Layout - layouts follow a pattern like this:
|
||||
# [[row]] represents a row in the application.
|
||||
# [[row.child]] represents either a widget or a column.
|
||||
# [[row.child.child]] represents a widget.
|
||||
#
|
||||
# All widgets must have the type value set to one of ["cpu", "mem", "proc", "net", "temp", "disk", "empty"].
|
||||
# All layout components have a ratio value - if this is not set, then it defaults to 1.
|
||||
# The default widget layout:
|
||||
[[row]]
|
||||
ratio=30
|
||||
[[row.child]]
|
||||
type="cpu"
|
||||
|
||||
[[row]]
|
||||
ratio=40
|
||||
[[row.child]]
|
||||
ratio=4
|
||||
type="mem"
|
||||
[[row.child]]
|
||||
ratio=3
|
||||
[[row.child.child]]
|
||||
type="disk"
|
||||
|
||||
[[row]]
|
||||
ratio=30
|
||||
[[row.child]]
|
||||
type="net"
|
||||
[[row.child]]
|
||||
type="proc"
|
||||
default=true
|
||||
|
||||
|
||||
# Filters - you can hide specific temperature sensors, network interfaces, and disks using filters. This is admittedly
|
||||
# a bit hard to use as of now, and there is a planned in-app interface for managing this in the future:
|
||||
[disk_filter]
|
||||
is_list_ignored = true
|
||||
list = ["/dev/loop\\d+"]
|
||||
regex = true
|
||||
case_sensitive = false
|
||||
whole_word = false
|
||||
|
||||
#[mount_filter]
|
||||
#is_list_ignored = true
|
||||
#list = ["/mnt/.*", "/boot"]
|
||||
#regex = true
|
||||
#case_sensitive = false
|
||||
#whole_word = false
|
||||
|
||||
#[temp_filter]
|
||||
#is_list_ignored = true
|
||||
#list = ["cpu", "wifi"]
|
||||
#regex = false
|
||||
#case_sensitive = false
|
||||
#whole_word = false
|
||||
|
||||
#[net_filter]
|
||||
#is_list_ignored = true
|
||||
#list = ["virbr0.*"]
|
||||
#regex = true
|
||||
#case_sensitive = false
|
||||
#whole_word = false
|
||||
@@ -0,0 +1,14 @@
|
||||
Port 22
|
||||
AddressFamily inet
|
||||
|
||||
AllowUsers {{ env.USERS }}
|
||||
|
||||
AcceptEnv LANG LC_*
|
||||
Subsystem sftp internal-sftp
|
||||
UsePAM yes
|
||||
PasswordAuthentication no
|
||||
PermitRootLogin no
|
||||
PrintLastLog no
|
||||
PrintMotd no
|
||||
ChallengeResponseAuthentication no
|
||||
X11Forwarding no
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
containers:
|
||||
dmz: [dmz]
|
||||
ct1: [mariadb, postgresql]
|
||||
credential:
|
||||
username: {{env.current_user}}
|
||||
shadow: {{env.shadow_passwd}}
|
||||
email: TO BE DEFINED # example user@domain.tld
|
||||
password: TO BE DEFINED
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
services: []
|
||||
containers: []
|
||||
@@ -0,0 +1,26 @@
|
||||
---
|
||||
containers:
|
||||
ct2: [ dokuwiki, dolibarr13 ]
|
||||
services:
|
||||
artcode.re:
|
||||
compta:
|
||||
app: dolibarr13
|
||||
port: 9001
|
||||
name: doli-artcode
|
||||
enabled: false
|
||||
pnrun.re:
|
||||
wiki:
|
||||
app: dokuwiki
|
||||
port: 80
|
||||
name: doku-pnrun
|
||||
enabled: false
|
||||
original:
|
||||
app: dokuwiki
|
||||
port: 8001
|
||||
name: doku-first
|
||||
enabled: false
|
||||
comptoirduvrac.re:
|
||||
gestion:
|
||||
app: odoo12
|
||||
port: 6003
|
||||
name: cdv
|
||||
@@ -0,0 +1,23 @@
|
||||
table inet firewall {
|
||||
|
||||
chain input {
|
||||
type filter hook input priority 0; policy drop;
|
||||
|
||||
# established/related connections
|
||||
ct state established,related accept
|
||||
|
||||
# loopback + lxdbr0 interface
|
||||
iifname lo accept
|
||||
iifname lxdbr0 accept
|
||||
|
||||
# icmp
|
||||
icmp type echo-request accept
|
||||
|
||||
# allow mDNS
|
||||
udp dport mdns accept
|
||||
|
||||
# allow SSH + GITEA + NGINX
|
||||
tcp dport {22, 2222, 80, 443} accept
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
---
|
||||
|
||||
authorized:
|
||||
pubkey: TO_BE_DEFINED
|
||||
|
||||
alert:
|
||||
to: TO_BE_DEFINED # example: mine@domain.tld
|
||||
from: TO_BE_DEFINED # example: no-reply@domain.tld
|
||||
smtp:
|
||||
server: TO_BE_DEFINED # example: mail.domain.tld
|
||||
username: TO_BE_DEFINED # example: postmaster@domain.tld
|
||||
password: TO_BE_DEFINED
|
||||
|
||||
timezone: # optional, example: UTC, Indian/Reunion, ...
|
||||
@@ -0,0 +1,2 @@
|
||||
{{ env.current_user }}: root
|
||||
root: {{ alert.to }}
|
||||
@@ -0,0 +1,6 @@
|
||||
set ask askcc append dot save crt
|
||||
#ignore Received Message-Id Resent-Message-Id Status Mail-From Return-Path Via Delivered-To
|
||||
set mta=/usr/bin/msmtp
|
||||
|
||||
alias {{ env.current_user }} root
|
||||
alias root {{ alert.to }}
|
||||
@@ -0,0 +1,26 @@
|
||||
# Set default values for all following accounts.
|
||||
defaults
|
||||
|
||||
# Use the mail submission port 587 instead of the SMTP port 25.
|
||||
port 587
|
||||
|
||||
# Always use TLS.
|
||||
tls on
|
||||
|
||||
# Set a list of trusted CAs for TLS. The default is to use system settings, but
|
||||
# you can select your own file.
|
||||
tls_trust_file /etc/ssl/certs/ca-certificates.crt
|
||||
|
||||
# The SMTP server of your ISP
|
||||
account alert
|
||||
host {{ alert.smtp.server }}
|
||||
from {{ env.fqdn }} <{{ alert.from }}>
|
||||
auth on
|
||||
user {{ alert.smtp.username }}
|
||||
password {{ alert.smtp.password }}
|
||||
|
||||
# Set default account to isp
|
||||
account default: alert
|
||||
|
||||
# Map local users to mail addresses
|
||||
aliases /etc/aliases
|
||||
@@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
|
||||
hostname=$(hostname -s)
|
||||
number=$(echo $hostname | grep -oP '[0-9]*$')
|
||||
hostname=${hostname%"$number"}
|
||||
rows=9
|
||||
|
||||
case $hostname in
|
||||
'prod')
|
||||
#print in RED
|
||||
echo -ne "\033[31;1m"
|
||||
;;
|
||||
'beta')
|
||||
rows=7
|
||||
#print in ORANGE
|
||||
echo -ne "\033[33;1m"
|
||||
;;
|
||||
'dev')
|
||||
rows=7
|
||||
#print in GREEN
|
||||
echo -ne "\033[33;1m"
|
||||
;;
|
||||
*)
|
||||
#print in GREEN
|
||||
echo -ne "\033[32;1m"
|
||||
;;
|
||||
esac
|
||||
|
||||
fullname="$hostname $number"
|
||||
figlet -f big "$fullname" | head -n$rows
|
||||
echo -ne "\033[0m"
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
FQDN=$(hostname --fqdn)
|
||||
IP_ADDRESS=$(hostname -I | cut -d ' ' -f1)
|
||||
DISTRO=$(lsb_release -d | cut -f2)
|
||||
KERNEL=$(uname -srm)
|
||||
UPTIME=$(uptime | awk -F'( |,|:)+' '{if ($7=="min") m=$6; else {if ($7~/^day/) {d=$6;h=$8;m=$9} else {h=$6;m=$7}}} {print d+0,"days"}')
|
||||
LOAD=$(cat /proc/loadavg)
|
||||
|
||||
echo "FQDN : $FQDN"
|
||||
echo "UPTIME: $UPTIME"
|
||||
echo "IPADDR: $IP_ADDRESS"
|
||||
echo "DISTRO: $DISTRO"
|
||||
echo "KERNEL: $KERNEL"
|
||||
echo "LOAD : $LOAD"
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
USERS=$(
|
||||
w -uh
|
||||
)
|
||||
|
||||
if [ -n "$USERS" ]; then
|
||||
echo '-----------------------------------------------'
|
||||
echo -e "${RED}Beware,${NC} there is another connected user${RED}"
|
||||
echo "$USERS"
|
||||
echo -e "${NC}-----------------------------------------------"
|
||||
fi
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/sbin/nft -f
|
||||
|
||||
flush ruleset
|
||||
|
||||
include "/etc/nftables.rules.d/*"
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
[[ "$PAM_TYPE" != "open_session" ]] && exit 0
|
||||
|
||||
if journalctl --since "1 minute ago" -u ssh | tac | grep Accepted -m1 | grep password; then
|
||||
{
|
||||
echo "User: $PAM_USER"
|
||||
echo "Remote Host: $PAM_RHOST"
|
||||
echo "Service: $PAM_SERVICE"
|
||||
echo "TTY: $PAM_TTY"
|
||||
echo "Date: $(date)"
|
||||
echo "Server: $(uname -a)"
|
||||
echo
|
||||
echo "Somebody has successfully logged in your machine, please be aware and acknowledge this event."
|
||||
} | mail -s "$PAM_SERVICE login on $(hostname -f) for account $PAM_USER" root
|
||||
fi
|
||||
exit 0
|
||||
@@ -0,0 +1,16 @@
|
||||
Port 2222
|
||||
AllowUsers {{env.current_user}}
|
||||
|
||||
AcceptEnv LANG LC_*
|
||||
Subsystem sftp /usr/lib/openssh/sftp-server
|
||||
ClientAliveInterval 120
|
||||
UsePAM yes
|
||||
MaxAuthTries 3
|
||||
|
||||
PasswordAuthentication no
|
||||
PermitRootLogin no
|
||||
PermitEmptyPasswords no
|
||||
PrintLastLog no
|
||||
PrintMotd no
|
||||
ChallengeResponseAuthentication no
|
||||
X11Forwarding no
|
||||
@@ -0,0 +1,6 @@
|
||||
Defaults env_reset
|
||||
Defaults mail_badpass
|
||||
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/TOOLBOX"
|
||||
|
||||
User_Alias ROOT = root, {{env.current_user}}
|
||||
ROOT ALL=(ALL:ALL) NOPASSWD: ALL
|
||||
@@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
Description=Startup Script
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
ExecStartPre=/bin/sleep 10
|
||||
ExecStart=/bin/bash -c "last -wad | mail -s 'server has been rebooted' root"
|
||||
RemainAfterExit=yes
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,7 @@
|
||||
{% for container in expanded.monitored.containers -%}
|
||||
check program {{ container }}.running
|
||||
with path "/root/lxc-is-running {{ container }}"
|
||||
depends on bridge
|
||||
if status != 0 then alert
|
||||
|
||||
{% endfor -%}
|
||||
@@ -0,0 +1,6 @@
|
||||
{% for host in expanded.monitored.hosts -%}
|
||||
check host {{ host.container }}.{{ host.port }} with address {{ host.container }}.lxd
|
||||
depends on {{ host.container }}.running
|
||||
if failed port {{ host.port }} protocol http for 2 cycles then alert
|
||||
|
||||
{% endfor -%}
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ "$2" == "up" ]]; then
|
||||
|
||||
ACTIVE_CONNECTION=$(nmcli -g NAME connection show --active | head -n1)
|
||||
ACTIVE_DEVICE=$(nmcli -g DEVICE connection show --active | head -n1)
|
||||
BRIDGE=$(ip addr show lxdbr0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1)
|
||||
GATEWAY=$(ip route | head -n1 | grep default | cut -d' ' -f3)
|
||||
logger -t NetworkManager:Dispatcher -p info "on $ACTIVE_DEVICE:$ACTIVE_CONNECTION up , change resolver to $BRIDGE,$GATEWAY"
|
||||
nmcli device modify "$ACTIVE_DEVICE" ipv4.dns "$BRIDGE,$GATEWAY"
|
||||
|
||||
if ! grep nameserver /etc/resolv.conf | head -n1 | grep -q "$BRIDGE"; then
|
||||
# sometimes, nmcli generates wrong order for namespace in resolv.conf, therefore forcing connection settings must be applied!
|
||||
logger -t NetworkManager:Dispatcher -p info "on $ACTIVE_DEVICE:$ACTIVE_CONNECTION nameservers wrong order detected, therefore forcing connection settings must be applied"
|
||||
nmcli connection modify "$ACTIVE_CONNECTION" ipv4.ignore-auto-dns yes
|
||||
nmcli connection modify "$ACTIVE_CONNECTION" ipv4.dns "$BRIDGE,$GATEWAY"
|
||||
logger -t NetworkManager:Dispatcher -p info "on $ACTIVE_DEVICE:$ACTIVE_CONNECTION nameservers wrong order detected, connection reloaded now!"
|
||||
nmcli connection up "$ACTIVE_CONNECTION"
|
||||
else
|
||||
logger -t NetworkManager:Dispatcher -p info "on $ACTIVE_DEVICE:$ACTIVE_CONNECTION nameservers look fine"
|
||||
fi
|
||||
else
|
||||
if [[ "$2" == "connectivity-change" ]]; then
|
||||
ACTIVE_DEVICE=$(nmcli -g DEVICE connection show --active | head -n1)
|
||||
logger -t NetworkManager:Dispatcher -p info "on $ACTIVE_DEVICE connectivity-change detected"
|
||||
fi
|
||||
fi
|
||||
@@ -0,0 +1,35 @@
|
||||
table inet lxd {
|
||||
chain pstrt.lxdbr0 {
|
||||
type nat hook postrouting priority srcnat; policy accept;
|
||||
|
||||
{%- if target != 'prod' %}
|
||||
# BLOCK SMTP PORTS
|
||||
tcp dport { 25, 465, 587 } ip saddr {{ firewall.bridge_subnet }} {%- if firewall.container_mail_passthrough %} ip saddr
|
||||
!= {{ env.ip_mail_passthrough }} {% endif %} log prefix "Drop SMTP away from container: " drop
|
||||
{% endif -%}
|
||||
|
||||
ip saddr {{ firewall.bridge_subnet }} ip daddr != {{ firewall.bridge_subnet }} masquerade
|
||||
}
|
||||
|
||||
chain fwd.lxdbr0 {
|
||||
type filter hook forward priority filter; policy accept;
|
||||
ip version 4 oifname "lxdbr0" accept
|
||||
ip version 4 iifname "lxdbr0" accept
|
||||
}
|
||||
|
||||
chain in.lxdbr0 {
|
||||
type filter hook input priority filter; policy accept;
|
||||
iifname "lxdbr0" tcp dport 53 accept
|
||||
iifname "lxdbr0" udp dport 53 accept
|
||||
iifname "lxdbr0" icmp type { destination-unreachable, time-exceeded, parameter-problem } accept
|
||||
iifname "lxdbr0" udp dport 67 accept
|
||||
}
|
||||
|
||||
chain out.lxdbr0 {
|
||||
type filter hook output priority filter; policy accept;
|
||||
oifname "lxdbr0" tcp sport 53 accept
|
||||
oifname "lxdbr0" udp sport 53 accept
|
||||
oifname "lxdbr0" icmp type { destination-unreachable, time-exceeded, parameter-problem } accept
|
||||
oifname "lxdbr0" udp sport 67 accept
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
table ip nat {
|
||||
chain prerouting {
|
||||
type nat hook prerouting priority dstnat; policy accept;
|
||||
iif "{{ nftables.wan_interface }}" tcp dport { 80, 443 } dnat to {{ nftables.dmz_ip }}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
# DEFAULT SERVER
|
||||
|
||||
# redirect any http request to https
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
return 301 https://$host$request_uri;
|
||||
}
|
||||
|
||||
# respond dummy nginx page
|
||||
server {
|
||||
listen 443 default_server ssl;
|
||||
include snippets/snakeoil.conf;
|
||||
root /var/www/html;
|
||||
index index.html index.htm index.nginx-debian.html;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
{% for service in expanded.services %}
|
||||
server {
|
||||
listen 443 http2 ssl;
|
||||
server_name {{ service.fqdn }};
|
||||
|
||||
{%- if target == 'dev' %}
|
||||
include snippets/snakeoil.conf;
|
||||
{%- else %}
|
||||
ssl_certificate /etc/letsencrypt/live/{{ service.domain }}/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/{{ service.domain }}/privkey.pem;
|
||||
{%- endif %}
|
||||
|
||||
location / {
|
||||
proxy_pass http://{{ service.container }}:{{ service.port }};
|
||||
{%- if service.app == 'odoo15' %}
|
||||
client_max_body_size 5M;
|
||||
{%- endif %}
|
||||
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
|
||||
{%- if target != 'prod' %}
|
||||
include snippets/banner_{{ target }}.conf;
|
||||
{%- endif %}
|
||||
}
|
||||
|
||||
{%- if service.app == 'odoo15' or service.app == 'odoo12' %}
|
||||
location /longpolling {
|
||||
proxy_pass http://{{ service.container }}:{{ service.port + 1000 }};
|
||||
}
|
||||
{%- endif %}
|
||||
}
|
||||
{% endfor %}
|
||||
@@ -0,0 +1,67 @@
|
||||
proxy_set_header Accept-Encoding "";
|
||||
|
||||
subs_filter '</body>' '
|
||||
<div class="betabanner_box">
|
||||
<div class="betabanner_ribbon"><span>BETA</span></div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
|
||||
.betabanner_box {
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
pointer-events: none;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.betabanner_ribbon {
|
||||
position: fixed;
|
||||
left: -5px;
|
||||
bottom : 0;
|
||||
z-index: 9999;
|
||||
overflow: hidden;
|
||||
width: 75px; height: 75px;
|
||||
text-align: right;
|
||||
}
|
||||
.betabanner_ribbon span {
|
||||
font-size: 10px;
|
||||
font-weight: bold;
|
||||
color: #FFF;
|
||||
text-transform: uppercase;
|
||||
text-align: center;
|
||||
line-height: 20px;
|
||||
transform: rotate(45deg);
|
||||
-webkit-transform: rotate(45deg);
|
||||
width: 100px;
|
||||
display: block;
|
||||
background: #79A70A;
|
||||
|
||||
background: linear-gradient(#ABC900 30%, #79A70A 61%);
|
||||
box-shadow: 5px 9px 27px -4px rgba(0, 0, 0, 1);
|
||||
|
||||
position: absolute;
|
||||
bottom: 16px;
|
||||
left: -21px;
|
||||
}
|
||||
.betabanner_ribbon span::before {
|
||||
content: "";
|
||||
position: absolute; left: 0px; top: 100%;
|
||||
z-index: -1;
|
||||
border-left: 3px solid #79A70A;
|
||||
border-right: 3px solid transparent;
|
||||
border-bottom: 3px solid transparent;
|
||||
border-top: 3px solid #79A70A;
|
||||
}
|
||||
.betabanner_ribbon span::after {
|
||||
content: "";
|
||||
position: absolute; right: 0px; top: 100%;
|
||||
z-index: -1;
|
||||
border-left: 3px solid transparent;
|
||||
border-right: 3px solid #79A70A;
|
||||
border-bottom: 3px solid transparent;
|
||||
border-top: 3px solid #79A70A;
|
||||
}
|
||||
</style>
|
||||
</body>
|
||||
';
|
||||
@@ -0,0 +1,65 @@
|
||||
proxy_set_header Accept-Encoding "";
|
||||
|
||||
subs_filter '</body>' '
|
||||
<div class="betabanner_box">
|
||||
<div class="betabanner_ribbon"><span>DEV</span></div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
|
||||
.betabanner_box {
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
pointer-events: none;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.betabanner_ribbon {
|
||||
position: fixed;
|
||||
left: -5px;
|
||||
bottom : 0;
|
||||
z-index: 9999;
|
||||
overflow: hidden;
|
||||
width: 75px; height: 75px;
|
||||
text-align: right;
|
||||
}
|
||||
.betabanner_ribbon span {
|
||||
font-size: 10px;
|
||||
font-weight: bold;
|
||||
color: #FFF;
|
||||
text-transform: uppercase;
|
||||
text-align: center;
|
||||
line-height: 20px;
|
||||
transform: rotate(45deg);
|
||||
-webkit-transform: rotate(45deg);
|
||||
width: 100px;
|
||||
display: block;
|
||||
background: linear-gradient(lightblue 30%, blue 81%);
|
||||
box-shadow: 5px 9px 27px -4px rgba(0, 0, 0, 1);
|
||||
|
||||
position: absolute;
|
||||
bottom: 16px;
|
||||
left: -21px;
|
||||
}
|
||||
.betabanner_ribbon span::before {
|
||||
content: "";
|
||||
position: absolute; left: 0px; top: 100%;
|
||||
z-index: -1;
|
||||
border-left: 3px solid #79A70A;
|
||||
border-right: 3px solid transparent;
|
||||
border-bottom: 3px solid transparent;
|
||||
border-top: 3px solid #79A70A;
|
||||
}
|
||||
.betabanner_ribbon span::after {
|
||||
content: "";
|
||||
position: absolute; right: 0px; top: 100%;
|
||||
z-index: -1;
|
||||
border-left: 3px solid transparent;
|
||||
border-right: 3px solid #79A70A;
|
||||
border-bottom: 3px solid transparent;
|
||||
border-top: 3px solid #79A70A;
|
||||
}
|
||||
</style>
|
||||
</body>
|
||||
';
|
||||
Reference in New Issue
Block a user