|
|
@ -613,9 +613,133 @@ PGHOST=172.19.0.2 PGUSER=postgres pgm ls |
|
|
|
tail -f /srv/datastore/data/cron/var/log/cron/letsencrypt-renew_script.log -n 200 |
|
|
|
#+END_SRC |
|
|
|
|
|
|
|
*** mysql |
|
|
|
|
|
|
|
**** docker sans compose |
|
|
|
|
|
|
|
***** backup régulier depuis l'hôte |
|
|
|
|
|
|
|
#+begin_src sh |
|
|
|
MYSQL_ROOT_PASSWORD=xxx |
|
|
|
MYSQL_CONTAINER=mailcowdockerized_mysql-mailcow_1 |
|
|
|
|
|
|
|
|
|
|
|
apt-get install -y mysql-client </dev/null |
|
|
|
|
|
|
|
cat <<EOF > ~/.my.cnf |
|
|
|
[client] |
|
|
|
password=${MYSQL_ROOT_PASSWORD} |
|
|
|
EOF |
|
|
|
chmod 600 ~/.my.cnf |
|
|
|
|
|
|
|
cat <<'EOF' > /usr/local/sbin/mysql-backup |
|
|
|
#!/bin/bash |
|
|
|
|
|
|
|
. /etc/shlib |
|
|
|
|
|
|
|
include common |
|
|
|
include pretty |
|
|
|
|
|
|
|
usage="$exname [--host HOST] [DATABASE...]" |
|
|
|
|
|
|
|
|
|
|
|
DBS=() |
|
|
|
host= |
|
|
|
while [ "$1" ]; do |
|
|
|
case "$1" in |
|
|
|
"--help"|"-h") |
|
|
|
print_usage |
|
|
|
exit 0 |
|
|
|
;; |
|
|
|
"--host") |
|
|
|
host="$2" |
|
|
|
shift |
|
|
|
;; |
|
|
|
*) |
|
|
|
DBS+=("$1") |
|
|
|
;; |
|
|
|
esac |
|
|
|
shift |
|
|
|
done |
|
|
|
|
|
|
|
|
|
|
|
mysql_opts=() |
|
|
|
if [ "$host" ]; then |
|
|
|
mysql_opts+=(-h "$host") |
|
|
|
fi |
|
|
|
|
|
|
|
m() { |
|
|
|
mysql "${mysql_opts[@]}" -Bs "$@" |
|
|
|
} |
|
|
|
|
|
|
|
md() { |
|
|
|
mysqldump "${mysql_opts[@]}" "$@" |
|
|
|
} |
|
|
|
|
|
|
|
mysql_databases() { |
|
|
|
echo "SHOW DATABASES" | m |
|
|
|
} |
|
|
|
|
|
|
|
mysql_tables() { |
|
|
|
local db="$1" |
|
|
|
echo "SHOW TABLES" | m "$db" |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if [ "${#DBS[@]}" == 0 ]; then |
|
|
|
DBS=($(mysql_databases)) || exit 1 |
|
|
|
fi |
|
|
|
|
|
|
|
mkdir -p /var/backups/mysql |
|
|
|
|
|
|
|
for db in "${DBS[@]}"; do |
|
|
|
if [[ "$db" == "information_schema" || "$db" == "performance_schema" || "$db" == "mysql" ]]; then |
|
|
|
continue |
|
|
|
fi |
|
|
|
echo "Dumping database $db..." >&2 |
|
|
|
# omitting all the rotation logic |
|
|
|
dst=/"var/backups/mysql/$db" |
|
|
|
[ -d "$dst.old" ] && rm -rf "$dst.old" |
|
|
|
[ -d "$dst" ] && mv "$dst" "$dst.old" |
|
|
|
mkdir -p "$dst.inprogress" |
|
|
|
(( start = SECONDS )) |
|
|
|
md "$db" --routines --no-data --add-drop-database --database "$db" | gzip --rsyncable > "$dst.inprogress/schema.sql.gz" |
|
|
|
tables=$(mysql_tables "$db") |
|
|
|
for table in $tables; do |
|
|
|
backup_file="$dst.inprogress/${table}.sql.gz" |
|
|
|
echo " Dumping $table into ${backup_file}" |
|
|
|
md "$db" "$table" | gzip --rsyncable > "$backup_file" || break |
|
|
|
done |
|
|
|
mv "$dst.inprogress" "$dst" |
|
|
|
[ -d "$dst.old" ] && rm -rf "$dst.old" |
|
|
|
(( elapsed = SECONDS - start )) |
|
|
|
echo " ..dumped $db to $dst ($(du -sh "$dst" | cut -f 1) in ${elapsed}s)" >&2 |
|
|
|
done |
|
|
|
EOF |
|
|
|
chmod +x /usr/local/sbin/mysql-backup |
|
|
|
|
|
|
|
cat <<EOF > /etc/cron.d/mysql-backup |
|
|
|
SHELL=/bin/bash |
|
|
|
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin |
|
|
|
|
|
|
|
0 * * * * root /usr/local/sbin/mysql-backup --host \$(docker-ip "$MYSQL_CONTAINER" 2>/dev/null | sed -r 's/ +/ /g' | cut -f 3 -d " ") | logger -t mysql-backup |
|
|
|
|
|
|
|
EOF |
|
|
|
|
|
|
|
mkdir -p /etc/mirror-dir && |
|
|
|
cat <<EOF >> /etc/mirror-dir/mirror-dir.conf |
|
|
|
/var/backups/mysql: |
|
|
|
exclude: |
|
|
|
- "/*.inprogress" |
|
|
|
EOF |
|
|
|
|
|
|
|
#+end_src |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*** rsync-backup |
|
|
|
|
|
|
|
**** Installation du backup |
|
|
|
**** Installation du backup via compose |
|
|
|
|
|
|
|
A faire depuis le serveur ayant des services à backupper. |
|
|
|
|
|
|
@ -650,6 +774,76 @@ EOF |
|
|
|
compose build mongo ## force the build of the new mongo image with regular dumps |
|
|
|
#+end_src |
|
|
|
|
|
|
|
**** Installation du backup sur un host debian |
|
|
|
|
|
|
|
Cela fonctionnera sur tout host ayant une base debian. |
|
|
|
|
|
|
|
#+begin_src sh |
|
|
|
DOMAIN=xxx.fr |
|
|
|
BACKUP_SERVER=core-06.0k.io:10023 |
|
|
|
## les répertoires à sauvegarder |
|
|
|
DESTS=( |
|
|
|
/var/backups |
|
|
|
/etc |
|
|
|
) |
|
|
|
|
|
|
|
## installation de rsync |
|
|
|
apt-get install -y rsync </dev/null |
|
|
|
|
|
|
|
## Création de l'utilisateur rsync |
|
|
|
mkdir -p /var/lib/rsync && \ |
|
|
|
groupadd -r rsync && \ |
|
|
|
useradd -r rsync -d /var/lib/rsync -g rsync && \ |
|
|
|
chown rsync:rsync /var/lib/rsync |
|
|
|
|
|
|
|
## Création de la clé ssh pour rsync |
|
|
|
su -c 'ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa -q -C "rsync@'"$DOMAIN" - rsync |
|
|
|
|
|
|
|
echo "copier-coller ceci dans le '/etc/compose/compose.yml' de ${BACKUP_SERVER%:*}:" |
|
|
|
echo |
|
|
|
cat <<EOF |
|
|
|
$DOMAIN: "$( |
|
|
|
cat /var/lib/rsync/.ssh/rsync_rsa.pub | |
|
|
|
fold -w 67 | sed -r 's/$/\\/g;2,$ s/^/ /g;$,$ s/\\$//g')" |
|
|
|
|
|
|
|
EOF |
|
|
|
|
|
|
|
cat <<EOF > /etc/cron.d/mirror-dir |
|
|
|
SHELL=/bin/bash |
|
|
|
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin |
|
|
|
|
|
|
|
$((RANDOM % 60)) * * * * root mirror-dir -d $BACKUP_SERVER -u rsync ${DESTS[@]} 2>&1 | logger -t mirror-dir |
|
|
|
EOF |
|
|
|
|
|
|
|
#+end_src |
|
|
|
|
|
|
|
les logs sont dans =/var/log/mirror.log=. |
|
|
|
|
|
|
|
Note, il est possible de spécifier des exclusions pour chaque |
|
|
|
répértoire mirroré de telle façon: |
|
|
|
|
|
|
|
#+begin_src sh |
|
|
|
cat <<EOF > /etc/mirror-dir/mirror-dir.conf |
|
|
|
/home: |
|
|
|
exclude: |
|
|
|
- /*/.cache/ |
|
|
|
- /*/.gvfs/ |
|
|
|
- /*/.local/share/Trash/files/ |
|
|
|
- /*/.Trash/ |
|
|
|
- /*/.mozilla/firefox/*/Cache/ |
|
|
|
- /*/.mozilla/firefox/*/storage/default/*/cache/ |
|
|
|
/media/data: |
|
|
|
exclude: |
|
|
|
- /binary/games/_steam |
|
|
|
- /incoming |
|
|
|
- /.Trash* |
|
|
|
- /lost+found |
|
|
|
- /backup/device |
|
|
|
EOF |
|
|
|
#+end_src |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* Interventions avancées |
|
|
|
|
|
|
|