Thứ Ba, 13 tháng 8, 2019

[IBM AIX-Script] Move the files based on Date.

1/ Using find command:

--Move all current directory(including subdirectory) to other. The files is Modified 7 day before.

find /setup -mtime +7 -exec mv "{}" /new_setup/ \;

--Move only file on current directory(Not including subdirectory) to other. The files is Modified 7 day before.

find /setup/* -prune -type f -mtime +7 -exec ls -alt {} \;
find /setup/* -prune -type f -mtime +7 -exec mv "{}" /setup/setup \;

2/ We use this option when list of files is too long(million files):

if [ $( pwd ) != "/setup" ]
then
cd /setup;
fi;
for v_date in "1" "02" "03" "04" "05" "06" "07" "08" "09" "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "30"
do
for v_file in $( ls -l | grep "$v_date 2017" | awk '{ print $9 }' )
do
print "Moving $v_file";
mv $v_file /new_setup;
done;
done;



Thứ Tư, 7 tháng 8, 2019

[ORACLE 11GR2] Resize datafile to Highest Block used in a script

/* Formatted on 8/7/2019 2:54:36 PM (QP5 v5.287) */
DECLARE
   v_HIGHBLOCK   NUMBER;
BEGIN
   FOR v_NEW_SIZE IN (SELECT FILE_ID, FILE_NAME
               FROM DBA_DATA_FILES
              WHERE TABLESPACE_NAME = 'TBS_Need_Resize')
   LOOP
      SELECT MAX (BLOCK_ID + BLOCKS)
        INTO v_HIGHBLOCK
        FROM DBA_EXTENTS
       WHERE TABLESPACE_NAME = 'TBS_Need_Resize' AND FILE_ID = v_NEW_SIZE.FILE_ID;

      EXECUTE IMMEDIATE
            'ALTER DATABASE DATAFILE '''
         || v_NEW_SIZE.FILE_NAME
         || ''' RESIZE '
         || (v_HIGHBLOCK * 8) / 1024
         || 'M';
   END LOOP;
END;
/