Join the community today
Register Now

PHP-FPM Beta Branch PHP binary + extensions backup/restore tool - php-binary-backup.sh

Discussion in 'Beta release code' started by eva2000, Dec 13, 2018.

Thread Status:
Not open for further replies.
  1. eva2000

    eva2000 Administrator Staff Member

    38,695
    8,548
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +13,131
    Local Time:
    12:18 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    Working on a PHP binary + PHP extensions backup and restore tool, tools/php-binary-backup.sh. This is a companion tool to tools/nginx-binary-backup.sh which allows you to backup and restore the Nginx binary.

    Both the Nginx and PHP binary backup tools will allow Centmin Mod 123.09beta01 and newer version users to compile a specific Nginx or PHP version once, back up the binary and then be able to restore or switch between Nginx or PHP binary versions without doing a full recompile which can take between 5-30+ minutes depending on the speed of your server. So these tools will allow you to instantly switch between versions which may be useful for testing, version comparison benchmarks etc.

    In future you could even speed up the initial Centmin Mod installation times by having the Nginx and PHP binaries already compiled and backed up on another server (of exact same CPU model) and just dropped into new Centmin Mod installs. You can get pretty creative with these Nginx and PHP binary backup/restore tools :D

    This is an example backup run
    Code (Text):
    ./php-binary-backup.sh backup                          
    --------------------------------------------------------
    backup current PHP binaries and extensions
    --------------------------------------------------------
    backup started...
    cp -af /usr/local/bin/php-cgi-b4strip /home/backup-phpbin/5.6.37-121218-161703/bin/php-cgi-b4strip
    cp -af /usr/local/bin/php-b4strip /home/backup-phpbin/5.6.37-121218-161703/bin/php-b4strip
    cp -af /usr/local/bin/php /home/backup-phpbin/5.6.37-121218-161703/bin/php
    cp -af /usr/local/bin/php-cgi /home/backup-phpbin/5.6.37-121218-161703/bin/php-cgi
    cp -af /usr/local/bin/php-config /home/backup-phpbin/5.6.37-121218-161703/bin/php-config
    cp -af /usr/local/bin/phpize /home/backup-phpbin/5.6.37-121218-161703/bin/phpize
    cp -af /usr/local/sbin/php-fpm-b4strip /home/backup-phpbin/5.6.37-121218-161703/sbin/php-fpm-b4strip
    cp -af /usr/local/sbin/php-fpm /home/backup-phpbin/5.6.37-121218-161703/sbin/php-fpm
    --------------------------------------------------------
    /home/backup-phpbin/5.6.37-121218-161703
    +-- bin
    |   +-- php
    |   +-- php-b4strip
    |   +-- php-cgi
    |   +-- php-cgi-b4strip
    |   +-- php-config
    |   +-- phpize
    +-- no-debug-non-zts-20131226
    |   +-- geoip.so
    |   +-- igbinary.so
    |   +-- imagick.so
    |   +-- mailparse.so
    |   +-- memcached.so
    |   +-- memcache.so
    |   +-- opcache.so
    |   +-- redis.so
    +-- php.d
    |   +-- a_customphp.ini
    |   +-- curlcainfo.ini
    |   +-- geoip.ini
    |   +-- igbinary.ini
    |   +-- imagick.ini
    |   +-- mailparse.ini
    |   +-- memcached.ini
    |   +-- memcache.ini
    |   +-- redis.ini
    |   +-- zendopcache.ini
    +-- sbin
       +-- php-fpm
       +-- php-fpm-b4strip
    
    4 directories, 26 files
    backup finished...
    --------------------------------------------------------
    backup created at /home/backup-phpbin/5.6.37-121218-161703
    --------------------------------------------------------
    

    Example backup listing
    Code (Text):
    ./php-binary-backup.sh list
    --------------------------------------------------------
    Listing of available PHP binaries and extensions backups
    --------------------------------------------------------
    /home/backup-phpbin/5.6.37-121218-161703
    /home/backup-phpbin/5.6.37-121218-162152
    /home/backup-phpbin/5.6.37-121218-162410
    /home/backup-phpbin/5.6.37-121218-162529
    --------------------------------------------------------
    

    This is an example restore run
    Code (Text):
    /php-binary-backup.sh restore /home/backup-phpbin/5.6.37-121218-161703
    --------------------------------------------------------
    Restore PHP binaries and extensions from backups
    --------------------------------------------------------
    --------------------------------------------------------
    backup current PHP binaries and extensions
    --------------------------------------------------------
    backup started...
    cp -af /usr/local/bin/php-cgi-b4strip /home/backup-phpbin/5.6.37-121218-162805/bin/php-cgi-b4strip
    cp -af /usr/local/bin/php-b4strip /home/backup-phpbin/5.6.37-121218-162805/bin/php-b4strip
    cp -af /usr/local/bin/php /home/backup-phpbin/5.6.37-121218-162805/bin/php
    cp -af /usr/local/bin/php-cgi /home/backup-phpbin/5.6.37-121218-162805/bin/php-cgi
    cp -af /usr/local/bin/php-config /home/backup-phpbin/5.6.37-121218-162805/bin/php-config
    cp -af /usr/local/bin/phpize /home/backup-phpbin/5.6.37-121218-162805/bin/phpize
    cp -af /usr/local/sbin/php-fpm-b4strip /home/backup-phpbin/5.6.37-121218-162805/sbin/php-fpm-b4strip
    cp -af /usr/local/sbin/php-fpm /home/backup-phpbin/5.6.37-121218-162805/sbin/php-fpm
    backup finished...
    --------------------------------------------------------
    backup created at /home/backup-phpbin/5.6.37-121218-162805
    --------------------------------------------------------
    
    restoring...
    
    cp -af /home/backup-phpbin/5.6.37-121218-161703/bin/php-cgi-b4strip /usr/local/bin
    cp -af /home/backup-phpbin/5.6.37-121218-161703/bin/php-b4strip /usr/local/bin
    cp -af /home/backup-phpbin/5.6.37-121218-161703/bin/php /usr/local/bin
    cp -af /home/backup-phpbin/5.6.37-121218-161703/bin/php-cgi /usr/local/bin
    cp -af /home/backup-phpbin/5.6.37-121218-161703/bin/php-config /usr/local/bin
    cp -af /home/backup-phpbin/5.6.37-121218-161703/bin/phpize /usr/local/bin
    
    -rwxr-xr-x   1 root root  21M Aug 23 23:38 php-b4strip
    -rwxr-xr-x   1 root root  21M Aug 23 23:38 php-cgi-b4strip
    -rwxr-xr-x   1 root root 4.5K Aug 23 23:38 phpize
    -rwxr-xr-x   1 root root 4.0K Aug 23 23:38 php-config
    -rwxr-xr-x   1 root root 9.2M Aug 23 23:38 php
    -rwxr-xr-x   1 root root 9.2M Aug 23 23:38 php-cgi
    cp -af /home/backup-phpbin/5.6.37-121218-161703/sbin/php-fpm-b4strip /usr/local/sbin
    cp -af /home/backup-phpbin/5.6.37-121218-161703/sbin/php-fpm /usr/local/sbin
    
    -rwxr-xr-x   1 root root  21M Aug 23 23:38 php-fpm-b4strip
    -rwxr-xr-x   1 root root 9.3M Aug 23 23:38 php-fpm
    
    cp -af /home/backup-phpbin/5.6.37-121218-161703/no-debug-non-zts-20131226 /usr/local/lib/php/extensions/no-debug-non-zts-20131226
    
    total 4.9M
    -rwxr-xr-x 1 root root 319K Aug 23 23:38 opcache.so
    -rwxr-xr-x 1 root root 285K Aug 23 23:39 igbinary.so
    -rwxr-xr-x 1 root root 377K Aug 23 23:40 memcached.so
    -rwxr-xr-x 1 root root 506K Aug 23 23:41 memcache.so
    -rwxr-xr-x 1 root root 238K Aug 23 23:41 mailparse.so
    -rwxr-xr-x 1 root root 1.3M Aug 23 23:42 imagick.so
    -rwxr-xr-x 1 root root  82K Aug 23 23:42 geoip.so
    -rwxr-xr-x 1 root root 1.8M Aug 23 23:42 redis.so
    drwxr-xr-x 2 root root 4.0K Aug 23 23:42 .
    drwxr-xr-x 3 root root 4.0K Dec 12 16:28 ..
    --------------------------------------------------------
    
    PHP 5.6.37 (cli) (built: Aug 23 2018 23:38:06)
    Copyright (c) 1997-2016 The PHP Group
    Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
       with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
    --------------------------------------------------------
    
    Usage: /usr/local/bin/php-config [OPTION]
    Options:
      --prefix            [/usr/local]
      --includes          [-I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib]
      --ldflags           []
      --libs              [-lcrypt  -lc-client  -lz -lexslt -ltidy -lresolv -lcrypt -ledit -lncurses -laspell -lpspell -lrt -lmcrypt -lltdl -lldap -llber -lstdc++ -lcrypt -lpam -lgmp -lt1 -lX11 -lXpm -lpng -lz -ljpeg -lvpx -lenchant -lcurl -lbz2 -lz -lrt -lm -ldl -lnsl  -lxml2 -lz -lm -ldl -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lssl -lcrypto -lcurl -lxml2 -lz -lm -ldl -lssl -lcrypto -lfreetype -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lssl -lcrypto -ldl -lm -licui18n -licuuc -licudata -ldl -lm -licuio -lxml2 -lz -lm -ldl -lnetsnmp -lssl -lssl -lcrypto -lm -lxml2 -lz -lm -ldl -lcrypt -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxslt -lxml2 -lz -ldl -lm -lssl -lcrypto -lcrypt ]
      --extension-dir     [/usr/local/lib/php/extensions/no-debug-non-zts-20131226]
      --include-dir       [/usr/local/include/php]
      --man-dir           [/usr/local/php/man]
      --php-binary        [/usr/local/bin/php]
      --php-sapis         [ cli embed fpm cgi]
      --configure-options [--enable-fpm --enable-opcache --enable-intl --enable-pcntl --with-mcrypt --with-snmp --enable-embed=shared --with-mhash --with-zlib --with-gettext --enable-exif --enable-zip --with-bz2 --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-shmop --with-pear --enable-mbstring --with-openssl --with-mysql=mysqlnd --with-libdir=lib64 --with-mysqli=mysqlnd --with-mysql-sock=/var/lib/mysql/mysql.sock --with-curl --with-gd --with-xmlrpc --enable-bcmath --enable-calendar --enable-ftp --enable-gd-native-ttf --with-freetype-dir=/usr --with-jpeg-dir=/usr --with-png-dir=/usr --with-xpm-dir=/usr --with-vpx-dir=/usr --with-t1lib=/usr --enable-pdo --with-pdo-sqlite --with-pdo-mysql=mysqlnd --enable-inline-optimization --with-imap --with-imap-ssl --with-kerberos --with-readline --with-libedit --with-gmp --with-pspell --with-tidy --with-enchant --with-fpm-user=nginx --with-fpm-group=nginx --disable-fileinfo --with-ldap --with-ldap-sasl --with-config-file-scan-dir=/etc/centminmod/php.d --with-xsl CC=/usr/bin/gcc CFLAGS=-O2 -m64 -march=core-avx2 -pipe -gsplit-dwarf CXX=/usr/bin/g++ CXXFLAGS=-O2 -m64 -march=core-avx2 -pipe -gsplit-dwarf]
      --version           [5.6.37]
      --vernum            [50637]
    --------------------------------------------------------
    
    fpmrestart
    Gracefully shutting down php-fpm  done
    Starting php-fpm  done
    --------------------------------------------------------
    Restored PHP binaries and extensions from
    /home/backup-phpbin/5.6.37-121218-161703
    --------------------------------------------------------
    


    To Do List
    • Need to add labels to backup directories to differentiate PGO vs non-PGO PHP 7+ built binaries.

     
    • Like Like x 1
  2. eva2000

    eva2000 Administrator Staff Member

    38,695
    8,548
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +13,131
    Local Time:
    12:18 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    Further testing of php-binary-backup.sh. Compiled PHP 7.2.14, ran backup and then compiled PHP 7.3.1 and ran backup again :)

    PHP 7.3.1 backup
    Code (Text):
    tools/php-binary-backup.sh backup
    --------------------------------------------------------
    backup current PHP binaries and extensions
    --------------------------------------------------------
    backup started...
    cp -af /usr/local/bin/php-cgi-b4strip /home/backup-phpbin/7.3.1-130119-042902/bin/php-cgi-b4strip
    cp -af /usr/local/bin/php-config /home/backup-phpbin/7.3.1-130119-042902/bin/php-config
    cp -af /usr/local/bin/php-cgi /home/backup-phpbin/7.3.1-130119-042902/bin/php-cgi
    cp -af /usr/local/bin/php-b4strip /home/backup-phpbin/7.3.1-130119-042902/bin/php-b4strip
    cp -af /usr/local/bin/phpize /home/backup-phpbin/7.3.1-130119-042902/bin/phpize
    cp -af /usr/local/bin/phpdbg /home/backup-phpbin/7.3.1-130119-042902/bin/phpdbg
    cp -af /usr/local/bin/php /home/backup-phpbin/7.3.1-130119-042902/bin/php
    cp -af /usr/local/sbin/php-fpm-b4strip /home/backup-phpbin/7.3.1-130119-042902/sbin/php-fpm-b4strip
    cp -af /usr/local/sbin/php-fpm /home/backup-phpbin/7.3.1-130119-042902/sbin/php-fpm
    --------------------------------------------------------
    /home/backup-phpbin/7.3.1-130119-042902
    +-- bin
    |   +-- php
    |   +-- php-b4strip
    |   +-- php-cgi
    |   +-- php-cgi-b4strip
    |   +-- php-config
    |   +-- phpdbg
    |   +-- phpize
    +-- no-debug-non-zts-20180731
    |   +-- geoip.so
    |   +-- igbinary.so
    |   +-- imagick.so
    |   +-- mailparse.so
    |   +-- mcrypt.so
    |   +-- memcached.so
    |   +-- memcache.so
    |   +-- opcache.so
    |   +-- redis.so
    +-- php.d
    |   +-- a_customphp.ini
    |   +-- a_customphp.ini-bak_130119-042544
    |   +-- curlcainfo.ini
    |   +-- geoip.ini
    |   +-- igbinary.ini
    |   +-- imagick.ini
    |   +-- mailparse.ini
    |   +-- mcrypt.ini
    |   +-- memcached.ini
    |   +-- memcache.ini
    |   +-- redis.ini
    |   +-- zendopcache.ini
    |   +-- zz-zendopcache.ini
    +-- sbin
        +-- php-fpm
        +-- php-fpm-b4strip
    
    4 directories, 31 files
    backup finished...
    --------------------------------------------------------
    backup created at /home/backup-phpbin/7.3.1-130119-042902
    --------------------------------------------------------
    

    listing PHP binary version backups - candidates for restore without re-compiling now :D
    Code (Text):
    tools/php-binary-backup.sh list
    --------------------------------------------------------
    Listing of available PHP binaries and extensions backups
    --------------------------------------------------------
    /home/backup-phpbin/7.2.14-130119-042320
    /home/backup-phpbin/7.3.1-130119-042902
    --------------------------------------------------------
    
     
    • Winner Winner x 1
..
Thread Status:
Not open for further replies.