Saturday, October 21, 2017

Dump windows scheduled tasks

From time to time, peoples asked me what is scheduled on the server.

Human readable format
schtasks /query /v /fo LIST
CSV
schtasks /query /v /fo CSV > tasks.csv

Friday, September 8, 2017

Increase the Size of an AWS EBS Cloud Volume Attached to a Linux Machine

  1. Stop the instance
  2. Make a snapshot of the volume that we want to increase
  3. Write down the attachment information
    Attachment information: i-f0cacda3 (PROD):/dev/sdf1 (attached)
    
  4. Detach the volume
  5. Create a new volume with larger size, pick the same zone, pick the snapshot that we create in Step #2
  6. Attach the new volume to the instance with the same attachment information (see Step #3)
  7. Start the instance
  8. ssh into the instance as usual
  9. df -h should still show the old size even we are using a larger volume
  10. Run resize2fs /dev/sdf1 to increase the size to match the larger volume
  11. Reboot (optional)

Saturday, September 2, 2017

Update ESXi Embedded Host Client

1. ssh into the ESXi host as root

2. Goto ESXi Embedded Host Client Site and copy the vib link.

3. install the vib
The time and date of this login have been sent to the system logs.

VMware offers supported, powerful system administration tools.  Please
see www.vmware.com/go/sysadmintools for details.

The ESXi Shell can be disabled by an administrative user. See the
vSphere Security documentation for more information.
[root@shuttle:~] esxcli software vib install -v http://download3.vmware.com/software/vmw-tools/esxui/esxui-signed-6360286.vib
Installation Result
Message: Operation finished successfully.
Reboot Required: false
VIBs Installed: VMware_bootbank_esx-ui_1.23.0-6360286
VIBs Removed: VMware_bootbank_esx-ui_1.8.0-4516221
VIBs Skipped: 
[root@shuttle:~]

Monday, August 28, 2017

iReport Builder and SVN keywords

In iReport Builder, there is no comment field to store SVN keywords.

As a workaround, I add a new "No Data" band, set the"print when expression" to "new Boolean (false)" and then I put a static field in the band.
REM SVN Revision Information: DO NOT REMOVE
REM $Revision: 2593 $
REM $Author: pchiu $
REM $Date: 2017-08-28 19:39:41 -0400 (Mon, 28 Aug 2017) $

This works as long as I don't need to display anything when the report is empty.

Sunday, August 27, 2017

zfs replace faulty disk

The disk already crashed. We have already pull it out and replace it with a good one. Now, we just need to fix zpool setup.

First we put the disk offline.
# zpool offline opt2 14610995796361758680
# zpool status -v opt2
  pool: opt2
 state: DEGRADED
status: One or more devices has been taken offline by the administrator.
        Sufficient replicas exist for the pool to continue functioning in a
        degraded state.
action: Online the device using 'zpool online' or replace the device with
        'zpool replace'.
  scan: scrub repaired 0 in 21h9m with 0 errors on Tue Jul 25 00:42:02 2017
config:

        NAME                      STATE     READ WRITE CKSUM
        opt2                      DEGRADED     0     0     0
          raidz1-0                DEGRADED     0     0     0
            da3                   ONLINE       0     0     0
            da4                   ONLINE       0     0     0
            14610995796361758680  OFFLINE      0     0     0  was /dev/da5


And then we replace it with the new device
# zpool replace opt2 da5 /dev/da5
# zpool status -v opt2
  pool: opt2
 state: DEGRADED
status: One or more devices is currently being resilvered.  The pool will
        continue to function, possibly in a degraded state.
action: Wait for the resilver to complete.
  scan: resilver in progress since Sun Aug 27 11:21:53 2017
        28.5G scanned out of 4.77T at 96.7M/s, 14h18m to go
        9.50G resilvered, 0.58% done
config:

        NAME                        STATE     READ WRITE CKSUM
        opt2                        DEGRADED     0     0     0
          raidz1-0                  DEGRADED     0     0     0
            da3                     ONLINE       0     0     0
            da4                     ONLINE       0     0     0
            replacing-2             OFFLINE      0     0     0
              14610995796361758680  OFFLINE      0     0     0  was /dev/da5/old
              da5                   ONLINE       0     0     0  (resilvering)

errors: No known data errors

Thursday, July 13, 2017

How to get A+ on SSL Labs running Tomcat

In my previous posting, we brought our tomcat server to Grade A on SSL Labs.
However, to archive A+, it requires more.

You need to enable HSTS. You can following this post to enable HSTS.

One problem I encountered with SSL Labs is the SNI. If we run the test under the default domain, HSTS test works. But if we run it under other domains, HSTS test will fail. So you end up with Grade A instead of A+.

So make sure you test it using your default domain.

Monday, July 3, 2017

ORDS Install/Upgrade (ORDS Versions 3.0 to 21.4)

Install

If your ords directory is e:\ords, use e:\ below. Do not include \ords

Stop Tomat
copy ords.war apex.war
rmdir $CATALINA_HOME/webapps/apex
copy apex.war $CATALINA_HOME/webapps/
java -jar apex.war configdir e:\
java -jar apex.war

Validate ORDS installation
java -jar apex.war validate

Run this if validation fails
java -jar apex.war schema

Configure Multiple Databases
Do not use workspace-id when adding APEX
java -jar apex.war setup --database dev
java -jar apex.war map-url --type base-path /dev dev
Start Tomcat


Upgrade


Stop Tomat
copy ords.war apex.war
rmdir $CATALINA_HOME/webapps/apex
copy apex.war $CATALINA_HOME/webapps/
java -jar apex.war configdir e:\
java -jar apex.war schema
Start Tomcat

Saturday, July 1, 2017

SSL Reverse Proxy using stunnel without using Oracle Wallet

EDIT: Using nginx is a better solution.

Making https call from oracle is a nightmare. As a minimum, you need to import the site certificate into Oracle wallet.

However, if there is any problem with the certificate, it is next to impossible to debug.
Oracle XE doesn't come with Oracle wallet, utl_http may not support SNI, all depends on the oracle database version, etc...

As a workaround, use stunnel to listen on localhost and let it talk to the remote site via https.

In this example, it is listening on 8103 protocol http and talk to remote site via 8443 protocol https.
doing http://127.0.0.1:8103 just like https://web1.remote.com:8443

stunnel.conf
[web1]
client = yes
accept = 127.0.0.1:8103
connect = web1.remote.com:8443
CAfile = ca-certs.pem

Friday, June 23, 2017

Oracle APEX dynamic style base on domain name

Add a new process with the following PL/SQL code to the login page Before Header Section.

Pre-Rendering->Before Header->Processes

DECLARE
  v_http_host varchar2(1000);
BEGIN 
  v_http_host := lower(owa_util.get_cgi_env('HTTP_HOST'));

  if v_http_host = 'domain1.com' or v_http_host like '%.domain1.com' then
    apex_theme.set_session_style(p_theme_number=> 242, p_name => 'my_style1');
  elsif v_http_host = 'domain2.com' or v_http_host like '%.domain2.com' then
    apex_theme.set_session_style(p_theme_number=> 242, p_name => 'my_style2');
  else 
    apex_theme.set_session_style(p_theme_number=> 242, p_name => 'my_style1');
  end if;
END;

Saturday, April 8, 2017

Backup Oracle database Data Definition to SVN

These scripts will export all database data definitions to individual text file and then commit to SVN.
Schedule a daily task to run this get_ddl_master.bat is like taking a daily backup of the database data definition.
You can use TortoiseSVN to check out the change over the time.

get_ddl_master.bat
This script will generate all the ddl statement, call sql.exe to dump the definitions and commit them to SVN.
@echo off
cd /D c:\WebAdmin
REM echo SET HEADING OFF       > get_ddl_all.sql
REM echo SET ECHO OFF        >> get_ddl_all.sql
REM echo SET PAGES 999        >> get_ddl_all.sql
REM echo SET LONG 90000     >> get_ddl_all.sql
REM echo SET TRIMSPOOL ON     >> get_ddl_all.sql
REM echo SET PAGESIZE 50000  >> get_ddl_all.sql
REM echo SET VERIFY OFF      >> get_ddl_all.sql
REM echo SET FEEDBACK OFF    >> get_ddl_all.sql
echo SET TERMOUT OFF     >> c:\WebAdmin\get_ddl_all.sql
"C:\Program Files\sqldeveloper\sqldeveloper\bin\sql.exe" sys/xxxx@berry.xxxx.local:1521:paris as sysdba @get_ddl_master.sql
echo exit; >> c:\WebAdmin\get_ddl_all.sql
"C:\Program Files\sqldeveloper\sqldeveloper\bin\sql.exe" sys/xxxx@berry.xxxx.local:1521:paris as sysdba @get_ddl_all.sql
REM
cd /D c:\WebAdmin\paris
svn cleanup c:\WebAdmin\paris
svn add * --force
svn -m "Nightly Backup" commit --username=chiup --password=xxxx --non-interactive
svn update

get_ddl_master.sql
This sql will generate all ddl statements. You should change the filter conditions to suit your needs.
SET HEADING OFF
SET ECHO OFF
SET PAGES 999
SET LONG 90000
set LINES 300
SET TRIMSPOOL ON
SET PAGESIZE 50000
SET VERIFY OFF
SET FEEDBACK OFF
SET TERMOUT OFF
cd c:\webAdmin
spool get_ddl_all.sql append
SELECT 'spool c:\webadmin\paris\' || OWNER || '.' || OBJECT_TYPE || '.' || OBJECT_NAME ||'.sql;'||
       chr(13)||chr(10)||
       'ddl '||owner||'.'||object_name||';'
sql_cmd
FROM ALL_OBJECTS
WHERE OBJECT_TYPE IN ('TABLE','PROCEDURE','FUNCTION','TRIGGER','PACKAGE','VIEW') 
AND OWNER NOT IN ('SYS','SYSTEM','SYSMAN','OUTLN','PORTAL','XDB','LBACSYS','OLAPSYS','WIRELESS','CTXSYS','EXFSYS')
order by owner, object_type, object_name;
spool off
exit