5 Replies Latest reply: Oct 24, 2012 4:14 PM by 954935 RSS

    ASMCMD delete files older than N days

    954935
      Hello,

      in ASM diskgroup,

      (under one directory)

      ASMCMD> ls -lt

      ...(thoudsands of log files looks like, for example, log_19.26718.790635667),

      how can I delete those files older than 10 days in one command line?


      thank you

      Edited by: 951932 on Oct 24, 2012 9:53 AM
        • 1. Re: ASMCMD delete files older than N days
          Osama_Mustafa
          usually to delete something in OS level Than X days
              find <path>\osama* -mtime +<days number> -exec rm {} \;
          I don't think it will work on asmcmd , si you have to delete them manually
          • 2. Re: ASMCMD delete files older than N days
            vlethakula
            , find command syntax in asmcmd. Looks like it doesn't support

            find [--type type] dir_name name_pattern (Oracle 11g R2 syntax)

            http://oracle.su/docs/11g/server.112/e10500/asm_util003.htm#BABECFIF

            If they are ARCHIVELOG files, refer

            How to clean old archive log without backup

            Edited by: vreddy on Oct 24, 2012 10:18 AM
            • 3. Re: ASMCMD delete files older than N days
              954935
              In fact, I know traditional command for this purpose, but I try to purge flashbacklogs,
              I have droped 'restore point' (in a standby database), the next step is to delete all useless old flashbacklogs in /flashback in ASM

              any shortcut to do this rather than manually rm -f each logs under that directory?


              ;-)

              cc:
              To remove uncessary Flashback Logs, you need to do the following:
              1) drop any Guaranteed Restore Points that you don’t need (e.g. drop restore point
              2) set the init parameter DB_FLASHBACK_RETENTION_TARGET adequately
              3) Log in as root and run the following statements:
              ls -lrt …/flashback|tail -100 =====> this is traditional OS, not ASM
              prepare delete statement for each file you want to remove
              (e.g. rm -f)


              thank you

              Edited by: 951932 on Oct 24, 2012 11:26 AM

              Edited by: 951932 on Oct 24, 2012 12:24 PM
              • 4. Re: ASMCMD delete files older than N days
                vlethakula
                Modification to the query used in thread,

                declare CURSOR cur IS
                select fname,file_number,gnum,gname from
                (SELECT file_number,gname,gnum, filnum, concat('+'||gname,sys_connect_by_path(aname, '/')) fname
                FROM (SELECT file_number,g.name gname, a.parent_index pindex, a.name aname,
                a.reference_index rindex, a.group_number gnum,a.file_number filnum
                FROM
                v$asm_alias a,v$asm_diskgroup g
                WHERE a.group_number = g.group_number
                )
                START WITH (mod(pindex, power(2, 24))) = 0
                CONNECT BY PRIOR rindex = pindex) output
                where gname='TEST' ---------->DG name
                and
                exists
                (select 'X' from v$asm_file b
                where b.file_number = output.file_number
                and b.group_number=output.gnum
                and b.type='FLASHBACK'
                and b.MODIFICATION_DATE<=TO_DATE('20121007','YYYYMMDD')
                );
                sqlstr VARCHAR2(250);
                BEGIN
                FOR cur_rec IN cur
                LOOP
                sqlstr := 'alter diskgroup '|| cur_rec.gname|| ' drop file ''' || cur_rec.fname ||''';';
                DBMS_OUTPUT.PUT_LINE(sqlstr);
                END LOOP;
                END;

                Edited by: vreddy on Oct 24, 2012 1:04 PM
                • 5. Re: ASMCMD delete files older than N days
                  954935
                  thank you very much.