blob: 9524557607d40f52422d9c5e080dcd4f8190fa11 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# implement "generate tech-support archive"
# usage: tech-support archive [ <filename> | <scp://> | <ftp://> ]
FLAG=2
REMOTE=0
DEFAULT_PATH=/opt/vyatta/etc/config/support
DEFAULT_GROUP=users
FILE_NAME=0
do_rotate ()
{
local count=`ls -t $DEFAULT_PATH/*.tech-support-archive.* 2>/dev/null |wc -l`
if (( count >= 5 )); then
local dfile=`ls -t $DEFAULT_PATH/*.tech-support-archive.* 2>/dev/null |tail -1`
rm -f $dfile >&/dev/null \
&& echo "Removed old tech-support output file '$dfile'"
fi
}
HOSTNAME=`hostname`
CURTIME=`date +%F-%H%M%S`
if [ -n "$1" ]; then
if [[ "$1" =~ scp:///* ]]; then
OUT="$HOSTNAME.tech-support-archive.$CURTIME"
REMOTE="1"
elif [[ "$1" =~ ftp:///* ]]; then
OUT="$HOSTNAME.tech-support-archive.$CURTIME"
REMOTE="1"
else
#file to be save locally
OUT="$1.$HOSTNAME.tech-support-archive.$CURTIME"
fi
else
OUT="$HOSTNAME.tech-support-archive.$CURTIME"
fi
if [[ $OUT != /* ]]; then
FILE_NAME=$OUT
do_rotate
# it's not absolute path. save in default path.
OUT="$DEFAULT_PATH/$OUT"
mkdir -p $OUT >& /dev/null
chgrp $DEFAULT_GROUP $OUT >& /dev/null
chmod 775 $OUT >& /dev/null
else
mkdir -p $OUT >& /dev/null
chgrp $DEFAULT_GROUP $OUT >& /dev/null
chmod 775 $OUT >& /dev/null
FILE_NAME=`echo $OUT | sed -e 's/\//\n/g' | tail -1`
fi
builtin cd "$OUT"
echo "Saving the archivals..."
sudo tar -zcf config.tgz /opt/vyatta/etc/config --exclude "*tech-support-archive*" >& /dev/null
sudo tar -zcf etc.tgz /etc >& /dev/null
sudo tar -zcf home.tgz /home >& /dev/null
sudo tar -zcf var-log.tgz /var/log >& /dev/null
sudo tar -zcf root.tgz /root >& /dev/null
sudo tar -zcf tmp.tgz /tmp >& /dev/null
sudo tar -zcf core-dump.tgz /var/core >& /dev/null
builtin cd "../"
sudo tar -zcvf $FILE_NAME.tgz $FILE_NAME >& /dev/null
sudo rm -r $FILE_NAME
OUT=$OUT.tgz
echo "Saved tech-support archival at $OUT"
if [ $REMOTE == "1" ]; then
perl /opt/vyatta/bin/vyatta-remote-copy.pl $1 $OUT $FLAG
fi
exit
|