AWStats migration script

JonBK

New member
Joined
Oct 12, 2011
Messages
3
Hi,

Not sure where best to post this, as the scripting section seemed aimed more at the pre-included scripts and DA API - so here will do. Mods, feel free to move it as needed.

Recently had need to migrate users between servers using the old AWStats plugin setup to one using the DA AWStats method. This means moving all the data from /etc/awstats/ to the relevant folder in /home/$user/domains/$domain/awstats/.data/ and updating the configuration file.

I'm sure it could be tidier, etc - but it does the trick nicely. Should be run on the new server once the accounts have been migrated (backup/restore on new box) and will fetch the awstats files from the old server. Make sure to put an SSH key in place first or you're going to get a lot of password requests.


Code:
#!/bin/bash
#Script for copying awstats data into updated folder structure.
#Make sure you have an SSH key in place or it's gonna be painful.
#
#Set $origserver below with hostname/ip of server containing existing awstats data
#
origserver=123.123.123.123
#
for i in `find /home -maxdepth 3 -type d -name domains | xargs ls -l | grep -v admin | awk '{ print $9 }' | tail -n +2`;
do
    for j in `find /home -maxdepth 3 -type d -wholename *domains/*$i*`;
    do
       scp root@$origserver:/etc/awstats/*$i* $j/awstats/.data/;
       k=`echo "$j" | cut -d/ -f3`;
       sed -e "s|DirData=\"/etc/awstats\"|DirData=\"/home/$k/domains/$i/awstats/.data\"|" -i $j/awstats/.data/*.conf
    done
done

Feel free to make use of it - but at your own risk.
 
on centos4.9 i have this error : find: invalid predicate `-wholename'

how can i fix it ?

Ah, you may run into that on older systems alright.

Try changing the line to:

for j in `find /home -maxdepth 3 -type d -path *domains/*$i*`;

If it throws an error, you may need to wrap it in quotes also:

for j in `find /home -maxdepth 3 -type d -path "*domains/*$i*"`;

I don't have a box running the older version of find to test it on, so I can't say for sure.
 
i dont try but its working with this :


#!/bin/bash
#Script for copying awstats data into updated folder structure.
#Make sure you have an SSH key in place or it's gonna be painful.
#
#Set $origserver below with hostname/ip of server containing existing awstats data
#
origserver=127.0.0.1
#
for i in `find /home -maxdepth 3 -type d -name domains | xargs ls -l | grep -v admin | awk '{ print $9 }' | tail -n +2`;
do
for j in `find /home -maxdepth 3 -type d -regex .*domains/.*$i.*`;
do
scp root@$origserver:/etc/awstats/*$i* $j/awstats/.data/;
k=`echo "$j" | cut -d/ -f3`;
sed -e "s|DirData=\"/etc/awstats\"|DirData=\"/home/$k/domains/$i/awstats/.data\"|" -i $j/awstats/.data/*.conf
done
done
 
i dont try but its working with this :
for j in `find /home -maxdepth 3 -type d -regex .*domains/.*$i.*`;

Good to hear you got that working. The older versions of find don't support a couple of the newer predicates such as wholepath, etc. That does the trick nicely though.

I assume it brought the data across okay? :) It's only been tested on one box so far.
 
Back
Top