@@ -54,6 +54,7 @@ public function onRunJob() {
5454 $ global_config = $ app ->getconf ->get_global_config ('sites ' );
5555 $ backup_dir = trim ($ server_config ['backup_dir ' ]);
5656 $ backup_mode = $ server_config ['backup_mode ' ];
57+ $ backup_tmp = trim ($ server_config ['backup_tmp ' ]);
5758 if ($ backup_mode == '' ) $ backup_mode = 'userzip ' ;
5859
5960 $ web_config = $ app ->getconf ->get_server_config ($ conf ['server_id ' ], 'web ' );
@@ -77,6 +78,15 @@ public function onRunJob() {
7778 if ( $ server_config ['backup_dir_is_mount ' ] == 'y ' && !$ app ->system ->mount_backup_dir ($ backup_dir ) ) $ run_backups = false ;
7879 if ($ run_backups ){
7980 $ web_array = array ();
81+
82+ system ('which pigz > /dev/null ' , $ ret );
83+ if ($ ret === 0 ) {
84+ $ use_pigz = true ;
85+ $ zip_cmd = 'pigz ' ; // db-backups
86+ } else {
87+ $ use_pigz = false ;
88+ $ zip_cmd = 'gzip ' ; // db-backups
89+ }
8090
8191 //* backup only active domains
8292 $ sql = "SELECT * FROM web_domain WHERE server_id = ? AND (type = 'vhost' OR type = 'vhostsubdomain' OR type = 'vhostalias') AND active = 'y' " ;
@@ -117,12 +127,16 @@ public function onRunJob() {
117127 if ($ backup_mode == 'userzip ' ) {
118128 //* Create a .zip backup as web user and include also files owned by apache / nginx user
119129 $ web_backup_file = 'web ' .$ web_id .'_ ' .date ('Y-m-d_H-i ' ).'.zip ' ;
120- exec ('cd ' .escapeshellarg ($ web_path ).' && sudo -u ' .escapeshellarg ($ web_user ).' find . -group ' .escapeshellarg ($ web_group ).' -print 2> /dev/null | zip -b /tmp --exclude=./backup\* ' .$ backup_excludes .' --symlinks ' .escapeshellarg ($ web_backup_dir .'/ ' .$ web_backup_file ).' -@ ' , $ tmp_output , $ retval );
121- if ($ retval == 0 || $ retval == 12 ) exec ('cd ' .escapeshellarg ($ web_path ).' && sudo -u ' .escapeshellarg ($ web_user ).' find . -user ' .escapeshellarg ($ http_server_user ).' -print 2> /dev/null | zip -b /tmp --exclude=./backup\* ' .$ backup_excludes .' --update --symlinks ' .escapeshellarg ($ web_backup_dir .'/ ' .$ web_backup_file ).' -@ ' , $ tmp_output , $ retval );
130+ exec ('cd ' .escapeshellarg ($ web_path ).' && sudo -u ' .escapeshellarg ($ web_user ).' find . -group ' .escapeshellarg ($ web_group ).' -print 2> /dev/null | zip -b ' . escapeshellarg ( $ backup_tmp ). ' --exclude=./backup\* ' .$ backup_excludes .' --symlinks ' .escapeshellarg ($ web_backup_dir .'/ ' .$ web_backup_file ).' -@ ' , $ tmp_output , $ retval );
131+ if ($ retval == 0 || $ retval == 12 ) exec ('cd ' .escapeshellarg ($ web_path ).' && sudo -u ' .escapeshellarg ($ web_user ).' find . -user ' .escapeshellarg ($ http_server_user ).' -print 2> /dev/null | zip -b ' . escapeshellarg ( $ backup_tmp ). ' --exclude=./backup\* ' .$ backup_excludes .' --update --symlinks ' .escapeshellarg ($ web_backup_dir .'/ ' .$ web_backup_file ).' -@ ' , $ tmp_output , $ retval );
122132 } else {
123133 //* Create a tar.gz backup as root user
124134 $ web_backup_file = 'web ' .$ web_id .'_ ' .date ('Y-m-d_H-i ' ).'.tar.gz ' ;
125- exec ('tar pczf ' .escapeshellarg ($ web_backup_dir .'/ ' .$ web_backup_file ).' --exclude=./backup\* ' .$ backup_excludes .' --directory ' .escapeshellarg ($ web_path ).' . ' , $ tmp_output , $ retval );
135+ if ($ use_pigz ) {
136+ exec ('tar pcf - --directory ' .escapeshellarg ($ web_path ).' . --exclude=./backup\* ' .$ backup_excludes .' | pigz > ' .escapeshellarg ($ web_backup_dir .'/ ' .$ web_backup_file ), $ tmp_output , $ retval );
137+ } else {
138+ exec ('tar pczf ' .escapeshellarg ($ web_backup_dir .'/ ' .$ web_backup_file ).' --exclude=./backup\* ' .$ backup_excludes .' --directory ' .escapeshellarg ($ web_path ).' . ' , $ tmp_output , $ retval );
139+ }
126140 }
127141 if ($ retval == 0 || ($ backup_mode != 'userzip ' && $ retval == 1 ) || ($ backup_mode == 'userzip ' && $ retval == 12 )) { // tar can return 1, zip can return 12(due to harmless warings) and still create valid backups
128142 if (is_file ($ web_backup_dir .'/ ' .$ web_backup_file )){
@@ -241,8 +255,8 @@ public function onRunJob() {
241255 $ command = "mysqldump -h " .escapeshellarg ($ clientdb_host )." -u " .escapeshellarg ($ clientdb_user )." -p " .escapeshellarg ($ clientdb_password )." -c --add-drop-table --create-options --quick --max_allowed_packet=512M --result-file=' " .$ db_backup_dir .'/ ' .$ db_backup_file ."' ' " .$ db_name ."' " ;
242256 exec ($ command , $ tmp_output , $ retval );
243257
244- //* Compress the backup with gzip
245- if ($ retval == 0 ) exec ("gzip -c ' " .escapeshellcmd ($ db_backup_dir .'/ ' .$ db_backup_file )."' > ' " .escapeshellcmd ($ db_backup_dir .'/ ' .$ db_backup_file ).".gz' " , $ tmp_output , $ retval );
258+ //* Compress the backup with gzip / pigz
259+ if ($ retval == 0 ) exec ("$ zip_cmd -c ' " .escapeshellcmd ($ db_backup_dir .'/ ' .$ db_backup_file )."' > ' " .escapeshellcmd ($ db_backup_dir .'/ ' .$ db_backup_file ).".gz' " , $ tmp_output , $ retval );
246260
247261 if ($ retval == 0 ){
248262 if (is_file ($ db_backup_dir .'/ ' .$ db_backup_file .'.gz ' )){
0 commit comments