===== Linux. backup =====
* [[https://www.cyberciti.biz/faq/howto-use-tar-command-through-network-over-ssh-session/|howto-use-tar-command-through-network-over ssh session ]]
* AI ''what is best way to backup dokuwiki on docker and save 2 last copies on google disk. if possible need to use only bash script''
===== Backup =====
==== SSH ====
* login to root with ssh key
#/etc/ssh/sshd_config
PermitRootLogin without-password
PubkeyAuthentication yes
service sshd restart
==== check session (specially for X) ====
ls /usr/bin/*session
==== check x application ====
dpkg -l|egrep -i "(kde|gnome|lxde|xfce|mint|unity|fluxbox|openbox)" | grep -v library
==== packages depends ====
apt-cache -o APT::Cache::GivenOnly=1 dotty gnome-system-tools | dot -T png > out.png
==== find GUI applications ====
apt-cache rdepends --installed libx11-6
==== get large packages ====
* wajig
sudo apt-get install wajig
wajig large
* Show Installed Package Size using dpkg-query
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n | tail -n 10
==== get installed meta package ( to clear gui) ====
awk 'BEGIN{
FS=" - ";
findmeta="apt-cache search . | grep -i \"metapackage\\|meta-package\"";
while ((findmeta | getline) > 0) meta[$1]=$2;
FS=" ";
findinstalled="dpkg --get-selections";
while ((findinstalled | getline) > 0) {
if ($1 in meta) print $1" - "meta[$1]
}
}'
==== clear fail2ban sqlite base ====
sqlite3 /var/lib/fail2ban/fail2ban.sqlite3 \
"DELETE FROM bans WHERE DATE(timeofban, 'unixepoch') < '2021-08-19'; VACUUM;"
==== full local backup to tmp ====
* gzip - fast
* tar gz -> root /
tar -czvf - --one-file-system --ignore-failed-read --exclude=/backup.tar.gz --exclude=/proc --exclude=/tmp --exclude=/mnt --exclude=/dev --exclude=/sys --exclude=/run --exclude=/media --exclude=/var/log --exclude=/var/cache/apt/archives --exclude=/var/lib/lxcfs / | pv | cat > /tmp/bot-ar-`date +%m-%d-%Y`.tgz
* tar gz -> /boot
tar -czvf - --one-file-system --ignore-failed-read /boot | pv | cat > /tmp/bot-ar-boot-`date +%m-%d-%Y`.tgz
* only if root available for login SSH
ssh root@bot.ip2u.ru 'cd / && tar -cvf - --exclude=/backup.tar.gz --exclude=/proc --exclude=/tmp --exclude=/mnt --exclude=/dev --exclude=/sys --exclude=/run --exclude=/media --exclude=/var/log --exclude=/var/lib/lxcfs/ --exclude=/var/cache/apt/archives / | gzip -9 ' | pv | cat > /mnt/d/backup/bot-ar/bot-ar-`date +%m-%d-%Y`.tgz
* brotli - very slow
tar -cf - --exclude=/backup.tar.gz --exclude=/proc --exclude=/tmp --exclude=/mnt --exclude=/dev --exclude=/sys --exclude=/run --exclude=/media --exclude=/var/log --exclude=/var/cache/apt/archives / | brotli | pv | cat > /tmp/bot-ar-`date +%m-%d-%Y`.tar.bt
* local run save to ssh
tar -cvf - --exclude=/backup.tar.gz --exclude=/proc --exclude=/tmp --exclude=/mnt --exclude=/dev --exclude=/sys --exclude=/run --exclude=/media --exclude=/var/log --exclude=/var/lib/lxcfs/ --exclude=/var/cache/apt/archives / | gzip -9 | ssh user@remote_server.example.com 'cat > /path/to/backup/bot-ar-`date +%m-%d-%Y`.tgz'