Passa al contenuto principale

Maintenance

1. Monitor

  • ps and pstree

    ps -aux | less
    pstree
    pstree -p | less
  • top, htop, glances

    top
    htop

    apt install glances
    glances
  • systemctl

    systemctl --help
    systemctl list-units
    systemctl list-sockets
    systemctl list-timers -l
    systemctl status
    systemctl cat nginx
    nano /lib/systemd/system/nginx.service
    systemctl show nginx
  • journalctl

    journalctl
    journalctl --help
    journalctl -k
    journalctl -b -u apache2 -r
    journalctl -u apache2 -f
  • /var/log/

    ls /var/log/
    ls /var/log/journal/
    tail /var/log/fail2ban.log

    ls /var/log/nginx/
    tail /var/log/nginx/error.log
    tail /var/log/nginx/access.log

    ls /var/log/postgresql/
    tail /var/log/postgresql/postgresql-15-main.log

    ls /var/log/letsencrypt/
    tail /var/log/letsencrypt/letsencrypt.log

    ls /var/log/apache2/
    tail /var/log/apache2/wp1-access.log -f

2. Backup/Restore

2.1 WordPress

  1. Backup:

    systemctl stop apache2

    cd /var/www/wp1/
    wp db export db.sql
    nano db.sql

    cd ..
    tar cfz wp1-$(date +%Y%m%d).tgz wp1/
    ls -lh
    tar tfz wp1-*.tgz | less

    systemctl start apache2

    It is safer to save the backup archive somewhere outside the VPS (using scp, sftp, rsync, etc.)

  2. Restore:

    systemctl stop apache2

    # delete current installation
    cd /var/www/wp1/
    wp db drop
    cd ..
    rm -rf wp1/
    ls

    # restore the backup
    tar xfz wp1-*.tgz
    cd wp1
    ls -al
    wp db create
    wp db import db.sql

    systemctl start apache2
  3. Create a backup script:

    cat <<'_EOF_' > ~/wp1-backup.sh
    #!/bin/bash -x

    systemctl stop apache2

    cd /var/www/wp1/
    wp db export db.sql
    cd ..
    tar cfz wp1-$(date +%Y%m%d).tgz wp1/
    mv *.tgz ~/

    systemctl start apache2
    _EOF_
  4. Test the backup script:

    cd
    chmod +x wp1-backup.sh
    rm /var/www/*.tgz
    ./wp1-backup.sh
    ls -lh
    tar tfz wp1-*.tgz | less

2.2 NextCloud

  1. Backup:

    occ maintenance:mode --on

    # backup DB
    cd /var/www/nc1/
    su -l postgres -c 'pg_dump --clean -d nc1db' > db.sql
    ls -lh db.sql
    nano db.sql

    cd ..
    tar cfz nc1-$(date +%Y%m%d).tgz nc1/
    ls -lh
    tar tfz nc1-*.tgz | less

    occ maintenance:mode --off
  2. Restore:

    systemctl stop nginx

    cd /var/www/
    rm -rf nc1/
    ls

    tar xfz ~/nc1-*.tgz
    ls
    cd nc1/
    su -l postgres -c "psql -d nc1db -f $(pwd)/db.sql"

    systemctl start nginx
  3. Create a backup script:

    cat <<'_EOF_' > ~/nc1-backup.sh
    #!/bin/bash -x

    occ='sudo -u www-data php /var/www/nc1/occ'
    $occ maintenance:mode --on

    cd /var/www/nc1/
    su -l postgres -c 'pg_dump --clean -d nc1db' > db.sql
    cd ..
    tar cfz nc1-$(date +%Y%m%d).tgz nc1/
    mv *.tgz ~/

    $occ maintenance:mode --off
    _EOF_
  4. Test the backup script:

    cd
    chmod +x nc1-backup.sh
    rm /var/www/*.tgz
    ./nc1-backup.sh
    ls -lh
    tar tfz nc1-*.tgz | less

3. Migrate

If the migration is just moving from one server to another, without changing the domain names, then it can be done like this:

  1. Make a backup on the old server.
  2. Transfer it to the new server.
  3. Restore it on the new server.

If domain names are changed, you should also change the siteurl and home options for WP. For NC, you should edit config/config.php and modify the domain names.

See also: Migrating Nextcloud

4. Update/Upgrade

note

Before an upgrade, it is strongly recommended to make a backup.

4.1 WordPress

It can be done from the web interface as well, but it is safer from the command line.

systemctl stop apache2

# Update WordPress core
wp core version
wp core update
wp core update-db

# Update all plugins
wp plugin update --all

# Update all themes
wp theme update --all

# Clear cache
wp cache flush

systemctl start apache2

4.2 NextCloud

It can be upgraded from the GUI, however an upgrade from the command line is recommended.

cd /var/www/nc1/
ls updater/

systemctl stop nginx

sudo -u www-data php updater/updater.phar --no-interaction

occ upgrade
occ app:update --all
occ db:add-missing-indices
occ db:convert-filecache-bigint

systemctl start nginx