summaryrefslogtreecommitdiff
path: root/scripts/tech-support-archive
diff options
context:
space:
mode:
authorDeepti Kulkarni <deepti@vyatta.com>2010-07-23 18:19:16 +0000
committerAn-Cheng Huang <ancheng@vyatta.com>2010-08-18 11:42:09 -0700
commit668bfe342afccb6f1c1288c1d6ae3a65167ffa40 (patch)
tree0403b653c3c665678537dd3e2c1bc59f66272946 /scripts/tech-support-archive
parent173b7bad08a6440e8892156cbdcf607475a25b65 (diff)
downloadvyatta-op-668bfe342afccb6f1c1288c1d6ae3a65167ffa40.tar.gz
vyatta-op-668bfe342afccb6f1c1288c1d6ae3a65167ffa40.zip
Adding 'generate tech-support archive'command
(cherry picked from commit 7d4d9c74b8105a27cc54f55ddb98ea90112e13c6)
Diffstat (limited to 'scripts/tech-support-archive')
-rwxr-xr-xscripts/tech-support-archive72
1 files changed, 72 insertions, 0 deletions
diff --git a/scripts/tech-support-archive b/scripts/tech-support-archive
new file mode 100755
index 0000000..977bce3
--- /dev/null
+++ b/scripts/tech-support-archive
@@ -0,0 +1,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