Rocky 9.x Owncloud upgrade by migrating to a new VM with updated version

From Notes_Wiki
Revision as of 05:50, 15 October 2022 by Saurabh (talk | contribs)

Home > Rocky Linux or CentOS > Rocky Linux 9.x > File Sharing > Owncloud > Upgrade and Migrate

To upgrade owncloud along with migrating to a new VM (Typically cloud or at least public) use:

  1. Stop web server on old server. For example
    /opt/owncloud-<ver>/ctlscript.sh stop apache
  2. Take one full backup of files and DB on backup server
    As such in below steps we are only doing migration to a new VM. We are not disturbing old VM. So backup is optional.
  3. Create a new VM for the migrated data along with upgraded owncloud version.
    The below steps were tested on Rocky Linux 9.x while migrating from owncloud 10.5 or 10.7 to 10.11
  4. Add approriate disk for required storage
  5. Login into VM via root SSH
  6. Set appropriate hostname
    hostnamectl set-hostname files-new.example.com
  7. Validate the storage disk, if required is visible at OS level. Create a physical partition for LVM purposes
    fdisk -l
    
    fdisk /dev/sd<n>
        n
        p
        1
        <enter>
        <enter>
        t
        8e
        w
  8. Install lvm2 package, if not present and create required filesystem. Mount the created filesystem on desired path via:
    dnf -y install lvm2
    pvcreate /dev/sd<n>1
    vgcreate vgfiles /dev/sd<n>1
    lvcreate -n lvfiles -l '100%VG' vgfiles
    mkfs.ext4 /dev/mapper/vgfiles-lvfiles
    blkid
    #Edit /etc/fstab and mount /dev/mapper/vgfiles-lvfiles on /opt
    mount -a 
    df -h
    Mount the Logical on desired final location of DataDirectory. If DataDirectory will not be in /opt but would be /mnt/files then mount the partition appropriately.
    Note Rocky 9.x Owncloud Manually moving DataDirectory. We can change DataDirectory during upgrade using this reference, if required.
  9. Install owncloud via:
    dnf -y install epel-release
    dnf -y install screen
    screen -d -RR byobu
    See CentOS 7.x screen
  10. Other new server setup related tasks:
    Increase swap to 4GB
    CentOS 7.x adding swap space using file
    Command line history retention
    Storing date / time along with commands in history
    Timezone
    CentOS 8.x Change system timezone
    Fail2ban
    CentOS 7.x fail2ban
  11. Install all OS level updates
    dnf update -y
  12. Disable selinux using:
    sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
    setenforce 0
    getenforce
  13. Allow ports 80 and 443 via firewalld using:
    firewall-cmd --zone=public --add-port=80/tcp --permanent
    firewall-cmd --zone=public --add-port=443/tcp  --permanent
    firewall-cmd --reload
    firewall-cmd --list-all
  14. (Optionally) Edit /etc/hosts on the new VM and add entry mapping VM interface IP (ip addr show) to desired FQDN
  15. On admin station add /etc/hosts entry to point to this new server via FQDN. This would help in testing the new setup before changing DNS entry to point to new server.
  16. Setup php 7.4 via Remi and install httpd, php, mariadb etc. via:
        dnf install -y http://rpms.remirepo.net/enterprise/remi-release-9.rpm
        dnf install -y dnf-utils
        dnf module reset php -y
        dnf module enable php:remi-7.4 -y
        dnf install -y php php-curl php-gd  php-intl php-json php-ldap php-mbstring php-mysqlnd php-xml php-process php-zip php-opcache mariadb-server httpd wget unzip tar
  17. Download OwnCloud server sources via
          cd /root
          wget https://download.owncloud.com/server/stable/owncloud-complete-latest.zip   #version 10.11 at time of writing
          unzip -q owncloud-complete-latest.zip
          mv owncloud /var/www/html
          chown -R apache:apache /var/www/html/owncloud
  18. Update default php resources values using Rocky 9.x Increase default PHP resources
    Without the increase in these limits we may see many blacklist errors on owncloud desktop client during sync
    Refer: https://central.owncloud.org/t/item-is-on-blacklist-how-to-verify-see-them-and-remove/23750/6 and https://github.com/owncloud/client/issues/2247
  19. Increase concurrency settings via Rocky 9.x Configure apache web server for concurrency to improve performance
  20. Start and enable services
    systemctl start mariadb
    systemctl enable mariadb
    systemctl start httpd
    systemctl enable httpd
  21. Read values of
    • dbname
    • dbtableprefix
    • dbuser
    • dbpassword
    from old installation via
    cd /opt/owncloud-<version>/apps/owncloud/htdocs
    unalias -a
    vi config/config.php
    In above commands replace '/opt/owncloud-<ver>/apps/owncloud/htdocs/' with old server Web server DocumentRoot appropriately
  22. Configure database on new machine. We can optionally configure DB with exact same vlaues of db-name, db-username and db-password as on old machine to avoid changing these parameters elsewhere.
    mysql_secure_installation
    mysql -u root -p #Even vanilla "mysql" seems to work!!
    CREATE DATABASE <dbname>;
    GRANT ALL ON <dbname>.* TO '<dbuser>'@'localhost' IDENTIFIED BY '<dbpassword>';
    FLUSH PRIVILEGES;
    exit
  23. Restore latest DB backup taken on old server to new server
    1. Add /etc/hosts entry on old server pointing to new server
    2. Allow keys from old server to new as authorized
      ssh-copy-id from old to new or copy manually
    3. Run below if DB backup is not recent (After entering maintenance mode)
      ls -lt /opt
      /opt/take-database-backup.sh
      Or take backup as explained at CentOS 8.x mariadb taking backup of large production databases
    4. Install rysnc and bzip2 on both old and new server, if not already present:
      dnf -y install rsync bzip2
    5. Rsync Database dump from old server to new server
      rsync -vtrp /opt/owncloud.sql.bz2 root@new-files.example.com:/opt/
    6. Restore DB backup copied via rsync on new server using:
      cd /opt
      bunzip2 owncloud.sql.bz2
      mysql
      use <db-name>
      source /opt/owncloud.sql
  24. Figure out various datadirectory in use. Although config/config.php mentions about only one DataDirectory the oc_accounts table might have home value which is not a sub-folder of config/config.php DataDirectory. In such cases we need to either copy/migrate all these other home folders also. To see various home folders in use, use below SQL query
    select * from oc_accounts;
    Look at value of home column. Validate that they are sub-folders of same parent DataDirectory and plan accordingly.
    We can move the home folders to a common location. But after that we must update various user home path appropriately. Also see Rocky 9.x Owncloud Manually moving DataDirectory
  25. IN PARALLEL copy files to same path in new machine
    #On new VM
    mkdir /opt/owncloud-10.0.10-4/apps/owncloud/data -p
    #on old server
    cd /opt/owncloud-<ver>/apps/owncloud/data
    rsync -a ./ root@new-files.sunilsanjay.com:$PWD/
    Assuming not trying to change DataDirectory via Rocky 9.x Owncloud Manually moving DataDirectory during migration.
    If you are trying to Change DataDirectory then rsync destination should be the new DataDirectory. Also need to follow DB and config related changes as explained at Rocky 9.x Owncloud Manually moving DataDirectory
  26. Create /var/www/html/owncloud/config/config.php by copying old config file using:
    #From old server copy config.php to new server /root/old-config.php
    cd /opt/owncloud-<ver>/apps/owncloud/htdocs/config
    rsync -vtrp config.php root@new-files.example.com:/root/old-config.php
    #On new server go to /var/www/html/owncloud/config
    cd /var/www/html/owncloud/config
    cp /root/old-config.php ./config.php
    chown apache:apache config.php
    In above commands replace '/opt/owncloud-<ver>/apps/owncloud/htdocs/' with old server Web server DocumentRoot appropriately
  27. Edit /var/www/html/owncloud/config/config.php and update at least following parameters:
    datadirectory - /opt/owncloud-10.0.10-4/apps/owncloud/data
    Set this as per new Data Directory desired. Could be /mnt/files
    As explained earlier if data directory is changing need to follow Rocky 9.x Owncloud Manually moving DataDirectory
    dbhost
    localhost:/var/lib/mysql/mysql.sock
    apps_paths
    Use paths as /var/www/html/owncloud/apps and /var/www/html/owncloud/apps-external
    openssl - Comment using /* */ php style multiline comments
  28. On new server create apps-external folder as specified in apps_path config parameter via:
    mkdir -p /var/www/html/owncloud/apps-external
    chmod 777 /var/www/html/owncloud/apps-external
  29. On new server, Only after DB restore (eg 'source owncloud.sql) finishes, try occ:upgrade and solve issues, if any one by one
    cd /var/www/html/owncloud
    sudo -u apache php -f occ upgrade
    For potential issues during upgrade also see old article at CentOS 7.x Upgrade owncloud to newer version or updated stack
  30. Login into new server http://<IP>/owncloud as admin and validate it is working.
    If you have added /etc/hosts entry in admin station the we can open the URL via FQDN also
  31. Change DNS entry and make it point to new server, if the migration and upgrade was successful
  32. Generate lets encrypt certificate on new server using (Owncloud can be in maintenance mode while doing this)
    1. Restart apache
      systemctl restart httpd
    2. Install required packages for SSL and Lets Encrypt
      dnf -y install mod_ssl
      dnf -y install certbot python3-certbot-apache
    3. Edit /etc/httpd/conf/httpd.conf with following values to create appropriate VirtualHost for certificate generation
      NameVirtualHost *:80
      
      <VirtualHost *:80>
          ServerAdmin saurabh@sbarjatiya.com
          DocumentRoot /var/www/html
          ServerName files.gbb.co.in
          ErrorLog logs/files.example.comerror_log
          CustomLog logs/files.example.com-access_log combined
      </VirtualHost>
    4. Request certificate via lets encrypt using:
      certbot --apache
    5. Use values such as:
      email
      saurabh@sbarjatiya.com
      Terms of service
      Y
      share email id
      Y
      Select domains
      1
    6. Edit /etc/httpd/conf.d/ssl.conf and replace SSLCertificateFile and SSLCertificateKeyFile with:
      SSLCertificateFile /etc/letsencrypt/live/files.example.com/fullchain.pem
      SSLCertificateKeyFile /etc/letsencrypt/live/files.example.com/privkey.pem
    7. Restart apache
      systemctl restart httpd
    8. Test the HTTPs url https://files.example.com/owncloud/
    9. Stop httpd till maintenance is completed (Perhaps File copying is still going on via rsync in parallel)
      systemctl stop httpd
    10. Configure SSL certificate auto renewal via
      1. Run below shell command
        certbot renew --dry-run
      2. In 'crontab -e' use below after randominzing minute(10) and hour (11) from below line:
        10 11 * * 0 /usr/sbin/certbot-auto renew
      3. Validate crontab config
        crontab -l
  33. Create redirect from / to /owncloud URL via
    cd /var/www/html
    wget www.sbarjatiya.com
    vi index.html
    -- Change URL=owncloud in HTTP META REFRESH LINE
    -- Optionally delete <title>
  34. Only After rsync of file finishes proceed further by, on new server set correct ownership of files:
    chown -R apache:apache /opt/owncloud-<ver>/apps/owncloud/data
    chown apache:apache /var/www/html/owncloud/config/*
    systemctl start httpd
    cd /var/www/html/owncloud
    sudo -u apache php -f occ maintenance:mode --off
    In above commands replace '/opt/owncloud-<ver>/apps/owncloud/data/' with new server desired / configured DataDirectory path appropriately
  35. Configure owncloud cron jobs via 'crontab -e' using:
    */5 * * * * /usr/bin/sudo -u apache /usr/bin/php -f /var/www/html/owncloud/occ system:cron
  36. Install sshpass and configure backup script via
    1. Install package
      dnf -y install sshpass
    2. Create /opt/take_database_backup.sh with
      #/bin/bash
      
      sshpass -p <db-password> mysqldump -u <db-username> -p <database-name> | bzip2 > /opt/owncloud.sql.bz2
      
      exit 0
    3. Set execute permissions\
      chmod +x /opt/take_database_backup.sh
    4. Configure appropriate backups for this server. During backup above created script can be run to take owncloud DB-backup in /opt
      For large deployments change backup script to use CentOS 8.x mariadb taking backup of large production databases
    5. Test and validate backups
  37. Logwatch configuration via:
    dnf -y install postfix logwatch
  38. Configure postfix by editing '/etc/postfix/main.cf'
    See step "Set at least following in /etc/postfix/main.cf for mail system to work properly: " from CentOS 8.x postfix send email through relay or smarthost with smtp authentication
  39. Restart postfix
    systemctl restart postfix
    systemctl enable postfix
  40. edit /etc/aliases for root email to go to appropriate ID
  41. Update aliases DB
    newaliases
  42. Test whether logwatch emails are coming by executing:
    /etc/cron.daily/0logwatch
    This assumes direct outgoing email from the current server (Eg linode)


There is older version of this article at: CentOS 7.x Upgrade owncloud to newer version or updated stack


Home > Rocky Linux or CentOS > Rocky Linux 9.x > File Sharing > Owncloud > Upgrade and Migrate