HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Installation/Configuration (http://www.howtoforge.com/forums/forumdisplay.php?f=27)
-   -   ISPconfig cleanup skript for unused webs? (http://www.howtoforge.com/forums/showthread.php?t=57807)

ochorocho 3rd July 2012 13:53

ISPconfig cleanup skript for unused webs?
 
Hello,

we're using ISPconfig for about 1 year now. It works really good, and satisfied our needs. :-)

Now, we wanted do cleanup a little bit. This means deleting webs!
In the web interface the webs are gone, but the folders including all data is still remain on the server.

Is there a skript to clean this up, like i saw one for ISPC2 ?

THX!

cheers,
ochorocho

till 3rd July 2012 14:17

There is no cleanup script required as ispconfig deletes the webs as soon as you delete them in the interface. If thats not the case on your server, then the server cronjob is stopped or failed to process the changes. If there are jobs stuck in the jobqueue (see monitor), then enable debugging as described in the FAQ.

bvbmedia 3rd May 2014 11:40

Script for retrieving orphan webfolders
 
I also had this issue. The symlinks we're removed but not the web folder.

So made a script that compares the /var/www folder against /var/clients/client1 to see which folders are orphan. Maybe it is useful to you.

/shopcvs/scripts/server/webserver_vhost_cleaner.php --continue=1 --summarize_disk_usage=1

SCAN FOR ORPHAN VHOSTS
Developed by BVB Media (http://www.bvbmedia.nl)
--------------------------
continue: 1
summarize_disk_usage: 1
--------------------------

Active vhosts: 18
Orphan vhosts: 44

The following folders can be deleted (but of course take care and do at your own risk).
/var/www/clients/client1/web116
/var/www/clients/client1/web120
/var/www/clients/client1/web124
/var/www/clients/client1/web96
/var/www/clients/client1/web130
/var/www/clients/client1/web107
/var/www/clients/client1/web122
/var/www/clients/client1/web140
/var/www/clients/client1/web135
/var/www/clients/client1/web18_bak_2012_12_04
/var/www/clients/client1/web117
/var/www/clients/client1/web136
/var/www/clients/client1/web137
/var/www/clients/client1/web128
/var/www/clients/client1/web133
/var/www/clients/client1/web34_bak_2012_12_05
/var/www/clients/client1/web141
/var/www/clients/client1/web142
/var/www/clients/client1/web103
/var/www/clients/client1/web95
/var/www/clients/client1/web129
/var/www/clients/client1/web102
/var/www/clients/client1/web59_bak_2012_12_05
/var/www/clients/client1/web134
/var/www/clients/client1/web118
/var/www/clients/client1/web123
/var/www/clients/client1/web26_bak_2012_12_04
/var/www/clients/client1/web139
/var/www/clients/client1/web1_bak_2012_11_28
/var/www/clients/client1/web1
/var/www/clients/client1/web138
/var/www/clients/client1/web125
/var/www/clients/client1/web126
/var/www/clients/client1/web108
/var/www/clients/client1/web60_bak_2012_12_05
/var/www/clients/client1/web119
/var/www/clients/client1/web29_bak_2012_12_04
/var/www/clients/client1/web105
/var/www/clients/client1/web57_bak_2012_12_05
/var/www/clients/client1/web30_bak_2012_12_04
/var/www/clients/client1/web106
/var/www/clients/client1/web54_bak_2012_12_05
/var/www/clients/client1/web13
/var/www/clients/client1/web127

Total size: 1129196652 Bytes (1077MB)

PHP code:

PHP Code:

#!/usr/bin/php
<?php
//####################################
//           developed by:           #
// Bas van Beek (bvbmedia@gmail.com  #
// (c)opyright to BVB Media BV 2014  #
//####################################
set_time_limit(186400);
ignore_user_abort(true);
function 
doPrint($content) {
    global 
$stats;
    
$stats['log'].=$content;
    return 
$content;
}

function 
clearvalue($input) {
    
$input=preg_replace("/\r|\n$/is"''$input);
    return 
$input;
}

function 
clearscreen($out=true) {
    
$clearscreen=chr(27)."[H".chr(27)."[2J";
    
fwrite(STDOUT$clearscreen);
}

function 
read($stopchar) {
    
$fp=fopen("php://stdin""r");
    
$in=fread($fp1); // Start the loop
    
$output='';
    while (
$in!=$stopchar) {
        
$output=$output.$in;
        
$in=fread($fp1);
    }
    
fclose($fp);
    return 
$output;
}

function 
multiple_choice($array$print_selected=1) {
    
// Display the choices
    
foreach ($array as $choice=>$value) {
        
fwrite(STDOUT"\t$choice: $value\n");
    }
    
// Loop until they enter 'q' for Quit
    
do {
        
// A character from STDIN, ignoring whitespace characters
        
do {
            
$selection=clearvalue(fgets(STDIN));
        } while (
trim($selection)=='');
        if (
array_key_exists($selection$array)) {
            if (
$print_selected) {
                
fwrite(STDOUT"{$array[$selection]} selected\n");
            }
            
$selected=$array[$selection];
            return 
$selected;
            break;
        }
    } while (
$selection!='q');
}

clearscreen();
echo 
'SCAN FOR ORPHAN VHOSTS'."\n";
echo 
'Developed by BVB Media (http://www.bvbmedia.nl)'."\n";
echo 
'--------------------------'."\n";
$commands_array=array();
if (
count($argv)>1) {
    foreach (
$argv as $key=>$value) {
        if (
$value=='--help') {
            
$string="Example:\n";
            
$string.="/shopcvs/scripts/server/webserver_vhost_cleaner.php --continue=1 --summarize_disk_usage=1\n";
            
fwrite(STDOUT$string);
            exit(
0);
        }
        if (
preg_match("/^--/"$value)) {
            
preg_match("/^--(.*?)\=(.*?)$/"$value$results);
            
$commands_array[$results[1]]=$results[2];
        }
    }
    
$needed_vars=array();
    
$needed_vars[]='continue';
    
$halt=0;
    foreach (
$needed_vars as $needed_var) {
        if (!
array_key_exists($needed_var$commands_array)) {
            
fwrite(STDOUT$needed_var." is not specified\n");
            
$halt=1;
        }
    }
    if (
$halt) {
        
fwrite(STDOUT"Script aborted.\n");
        exit(
0);
    }
    foreach (
$commands_array as $key2=>$value2) {
        
fwrite(STDOUT$key2.": ".$value2."\n");
    }
} else {
    die();
}
echo 
'--------------------------'."\n";
$stats=array();
$stats['activeVhosts']=0;
$stats['orphanVhosts']=0;
$stats['diskUsage']=0;

$path='/var/www';
$records=array();

$excludeFolders=array();
$excludeFolders[]='.';
$excludeFolders[]='..';
$excludeFolders[]='backup';
$excludeFolders[]='clients';
$excludeFolders[]='mysql';
if (
$handle=opendir($path)) {
    while (
false!==($entry=readdir($handle))) {
        if (!
in_array($entry$excludeFolders)) {
            if (
is_link($path.'/'.$entry)) {
                
// symlink
                
$records['symlinks'][$entry]=$path.'/'.$entry;
                
$readlink=readlink($path.'/'.$entry);
                if (
$readlink) {
                    
$readlink=substr($readlink0strlen($readlink)-1);
                    
$records['symlinks_targets'][]=$readlink;
                    
$stats['activeVhosts']++;
                }
            }
        }
    }
    
closedir($handle);
}
$path='/var/www/clients/client1';
if (
$handle=opendir($path)) {
    while (
false!==($entry=readdir($handle))) {
        if (!
in_array($entry$excludeFolders)) {
            if (!
is_link($path.'/'.$entry)) {
                
$records['folders'][$entry]=$path.'/'.$entry;
            }
        }
    }
    
closedir($handle);
}
foreach (
$records['folders'] as $folder) {
    if (!
in_array($folder$records['symlinks_targets'])) {
        
$records['foldersToDelete'][]=$folder;
        
$stats['orphanVhosts']++;
    }
}
echo 
"\n";
echo 
'Active vhosts: '.$stats['activeVhosts']."\n";
echo 
'Orphan vhosts: '.$stats['orphanVhosts']."\n";
if (!
$records['foldersToDelete']) {
    echo 
"\n".'Everything is clean. No orphan vhosts found.'."\n";
} else {
    echo 
"\n".'The following folders can be deleted (but of course take care and do at your own risk).'."\n";
    foreach (
$records['foldersToDelete'] as $folder) {
        echo 
$folder."\n";
        if (
$commands_array['summarize_disk_usage']) {
            
$command="du -bs ".$folder."|cut -d \\/ -f 1";
            
$size=exec($command);
            
$stats['diskUsage']+=$size;
        }
    }
    if (
$stats['diskUsage']) {
        echo 
"\n".'Total size: '.$stats['diskUsage'].' Bytes ('.round(($stats['diskUsage']/1024/1024), 0).'MB)'."\n";
    }
}
?>



All times are GMT +2. The time now is 09:14.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.