How to send a backup of a Barracuda NG Firewall via email
How to create a backup of the firewall:
1 2 |
cd /opt/phion/config/configroot/ phionar cdl /tmp/$(date "+%Y%m%d")-$(hostname)-backup.par * |
How to build an email with attachment with bash and openssl:
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 |
#!/usr/bin/env bash # # Author: Brice Lilot FILE=/tmp/mail.txt DATE=$(date "+%a, %d %b %Y %H:%M:%S %z") SUBJECT="Firewall Backup" CUSTOMER="Customer" echo "HELO MAIL.CUSTOMER.TLD" > $FILE echo "MAIL FROM:<$FROM>" >> $FILE echo "RCPT TO:<$1>" >> $FILE echo "DATA" >> $FILE echo "From: Firewall $CUSTOMER <$FROM>" >> $FILE echo "To: <$1>" >> $FILE echo "Date: $DATE" >> $FILE echo "Subject: [$CUSTOMER] Firewall Backup - Done" >> $FILE echo "MIME-Version: 1.0" >> $FILE echo "Content-Type:multipart/mixed;boundary="boundary-yradnuob"" >> $FILE echo "--boundary-yradnuob" >> $FILE echo "Content-Type: text/plain; charset=us-ascii" >> $FILE cat <<<>>>$FILE Backup successful Date: $DATE Filename: $2 EOF echo "--boundary-yradnuob" >> $FILE echo "Content-Type: application/octet-stream;name="$2"" >> $FILE echo "Content-Transfer-Encoding:base64" >> $FILE echo "Content-Disposition:attachment;filename="$2"" >> $FILE openssl base64 > $FILE echo "" >> $FILE echo "" >> $FILE echo "." >> $FILE echo "QUIT" >> $FILE echo "" >> $FILE |
How to send an email via Netcat:
1 |
nc $SERVER $PORT < /tmp/mail.txt |
Enabling dayligth saving time on Huawei Switches
How to enable daylight saving time on Huawei Switches: CEST:
1 |
clock daylight-saving-time CEST repeating 01:00 last Sun Mar 01:00 last Sun Oct 01:00 |
Rebuild indexes from SolarWinds Orion Server
SolarWinds sell a great solution for monitoring your network and your servers, but regarding the maintenance of the server itself or its database, there is a leak. After serveral months of intensive utilization, indexes from all tables become fragmented and the responsiveness from the SolarWinds Orion decrease a lot. At the beginning, in less than 10 seconds everything was finished but now, you can have a break and take a coffee and be back to see slowly the result. I decided to build a script (Basic MS SQL) to select the most fragmented table (and the most heavy) and to build the “Rebuild script”.
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 |
SET NOCOUNT ON DECLARE @myTables TABLE( tab varchar(256) NOT NULL, ind varchar(256) NOT NULL ); Declare @tabt varchar(256); Declare @indt varchar(256); INSERT INTO @myTables SELECT dbtables.[name] as 'Table', dbindexes.[name] as 'Index' FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, NULL) AS indexstats INNER JOIN sys.tables dbtables on dbtables.[object_id] = indexstats.[object_id] INNER JOIN sys.schemas dbschemas on dbtables.[schema_id] = dbschemas.[schema_id] INNER JOIN sys.indexes AS dbindexes ON dbindexes.[object_id] = indexstats.[object_id] AND indexstats.index_id = dbindexes.index_id WHERE indexstats.database_id = DB_ID() and (indexstats.page_count * indexstats.avg_fragmentation_in_percent) > 10000 --ORDER BY indexstats.avg_fragmentation_in_percent desc ORDER BY indexstats.page_count * (indexstats.avg_fragmentation_in_percent) desc; WHILE (SELECT COUNT(*) FROM @myTables) > 0 BEGIN SELECT TOP 1 @indt = ind, @tabt = tab FROM @myTables; DELETE @myTables WHERE ind = @indt AND tab = @tabt; PRINT 'USE [SolarWindsOrion]' PRINT 'GO' PRINT 'ALTER INDEX '+@indt+' ON [dbo].['+@tabt+'] REBUILD PARTITION = ALL WITH ( PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, ONLINE = OFF, SORT_IN_TEMPDB = OFF )'; PRINT 'GO' PRINT 'PRINT ''The index '+@indt+' from '+@tabt+' has been defragmented'''; END; |
It’s not perfect (it’s crappy, I know) but it solved my problem.