Alert for orphaned files (.mdf, .ldf & .ndf)

Hi, 
Has anyone got any code that can scan all attached drives/directories for database files and compare them to what the instance says are attached files?  I have some code which works but you have specify the directories to monitor.  
I know that I could do this in C# quite easily but I'm wondering if it could all be done in T-SQL. Also could I run into permissions issues if the process is scanning all directories. 
This is the SQL code I have 
CREATE PROCEDURE [dbo].[UspReport_OrphanedDatabaseFile]
@FileLocation VARCHAR(512)
AS
BEGIN
SET NOCOUNT ON;
-- create temporary table to capture file names from directory.
if object_id('tempdb..#folderandfileinfo') is not null
BEGIN 
  DROP TABLE #folderandfileinfo;
  END; 
create table #folderandfileinfo
  cid int identity(1,1) primary key clustered,
subdirectory varchar(255),
depth int,
 isfile int
exec master..xp_dirtree @FileLocation, 1, 1;
select
  @FileLocation AS [Path Location] ,
  subdirectory AS [Orphaned Data Files] 
from
  #folderandfileinfo
where
  subdirectory like '%df' -- compares ONLY to .mdf, .ndf, and .ldf
  and subdirectory not in
  select right(smf.physical_name, charindex('\', reverse('\' + smf.physical_name)) - 1) 
  from
  sys.master_files smf join sys.databases sd on smf.database_id = sd.database_id
order by
  subdirectory asc;
END

What if you have several SQL Server instances on one machine (as I have)? You would have to check all instance with all found files?
What if other file extentions are used? MDF/NDF/LDF are common, but not a must, you can use any other file ext.
Hi, 
Good points.  
Typically there is only one instance per server here (apart from the DEV server).  I can live with the procedure returning hits on non db files.  Basically if any are reported then I would investigate and delete if required. 

Similar Messages

  • How to raise Alerts for Sender File Channel

    Hi All,
    For Sender File Channels , we can find out the status of the adapter through RWB as to whether it is Content Conversion related exception or Folder path not found exception & etc .
    I wanted to know as to whether there is any way where can rasie alerts for Sender File Channels (similar to what we do for Reciever File Channels) as well.
    Regards
    Vinay P.

    I found it myself .
    In Alert Configuration while we are adding alerts for a particular aler category , the following parameters needs to be checked .
    Connected to Message : Not Relevant
    Sender Service/Party/Interface/Namespace needs to be mentioned.
    Adapter Type should be selected as File

  • Set alert for log file free space

    We need to set an alert in case the log file fills up to a certain level (ST04 - Space usage - Total log size / Free space)
    Which parameter should we set in solman for this?
    Thanks in advance

    setup your CCMS agents to monitor the log files
    http://help.sap.com/saphelp_nw04/helpdata/en/65/f3156d443e744abe15dbe14e4e32b5/content.htm

  • URLs in orphaned file list?

    when I check for orphaned files on my very old, very messy
    website I see urls like "/http:/java.sun.com",
    "mailto:[email protected]" and nothing happens when I choose
    "open file". I can delete them from the list but when I run the
    orphaned files check again they're all back! what's going on?
    I recognize most of these as files and links that were
    deleted long ago (them and the pages that linked to them). How is
    dreamweaver finding these links and what are they doing in the
    orphaned files list?

    > I recognize most of these as files and links that were
    deleted long ago
    Under the main dw menu->Site->Advanced->Rebuild Site
    Cache.
    Alan
    Adobe Community Expert, dreamweaver
    http://www.adobe.com/communities/experts/

  • "anchor" links and Orphaned files ???

    I have a number of "anchor" links to a file named "constitution.html".  This is to allow one to jump to a specific part of a VERY long page (the complete constitution).  The links are like this one constitution.html#a3s1.  When I check in DW CS5 for Orphaned files DW reports this file "constitution.html" as an orphaned file.
    Is this normal because of the anchor links part of the link?
    Or do I have some unknown problem with my code?
    The links to this "orphaned" file are working OK.
    Thanks

    Is this normal because of the anchor links part of the link?
    Yes.  Sorry....

  • Customize orphan file report?

    Using DW CS6 (Windows 7 if that makes a difference) can we customize a broken link/orphan file report in any way? I've been searching around for this for a while and haven't found anything so I'm assuming no but...
    The problem:
    We use Adobe Contribute with rollbacks enabled so it will create file strings that contain "_bak" when a page is published to our development server. When generating a report looking for orphan files, I have to weed through thousands (around 10,000 lines in an Excel file) of these false orphans to end up with a list of real orphans. Is there a way to search the site and ignore any files/folders with _bak in the string?
    Thanks!

    Thanks both of you. I guess I'd better brush up on my Excel skills.
    And I agree Nancy. I never use or trust it to find broken links. I'm strictly using it to locate orphan files that our users neglected to delete from the site. I've used Xenu in the past but found another tool called Deep Trawl that I've been using. Not that it's any better really. I just like the interface a little more.
    Thanks again!

  • Ideal disk setup for MDFs, LDFs, TempDB, and cube files?

    I'm about to build an enterprise SQL Server that will run both OLTP and our data warehouse (OLAP).  What is the proper disk setup for data files, please?  Is it something like:
    1 for MDFs
    1 for LDFs
    1 for TempDB
    1 for OLAP files
    Or something close to that?
    Thanks for any guidance.

    Please take a look at these URLs:
    How to configure the hard disks for optimal performance?
    Disk Partition Alignment Best Practices for SQL Server
    SQL Server Storage Best Practices
    T-SQL Articles
    T-SQL e-book by TechNet Wiki Community
    T-SQL blog

  • SQL mdf file size vs ndf

    Hi,
    If multiple database files are created does the mdf file hold any of the row data or does is it exclusively hold the table definitions?
    If the mdf file is exclusively used to hold table definitions i'm assuming I can size it quite small?
    Thanks 
    Mr Shaw

    As Olaf said, it completely depends on how and where you create the ndf file.
    If you create additional ndf files in the primary file group itself, then it utilizes both the mdf and ndf file in a round robin fashion and both grow at the same pace.
    If you want you can segregate mdf and ldf by different methods.
    One option is to keep the mdf file only for system objects and all user objects in ndf files . Check the "Filegroup" section in this article -
    http://www.codeproject.com/Articles/43629/Top-steps-to-optimize-data-access-in-SQL-Serv
    Another option is to move just indexes or just few objects .Check this article for moving data from mdf to ndf -
    http://blogs.msdn.com/b/sqlserverfaq/archive/2011/08/02/moving-data-from-the-mdf-file-to-the-ndf-file-s.aspx
    Regards, Ashwin Menon My Blog - http:\\sqllearnings.com

  • Alert Email notification for Log file alerts

    Hi,
    Scenario: SCOM 2012 R2 UR4.
    There are created unix/linux log file monitoring objects. In SCOM console I can view alerts related to unix/linux log file monitoring. Email notification is: Warning or Critical for severity, and, Medium or High for priority. The alerts for unix/linux log
    file are severity warning and priority medium.
    In my inbox there are emails for alerts (Warning or Critical for severity, and, Medium or High for priority) except for unix/linux monitoring.
    The question is:
    How to enable email notification for unix/linux log file monitoring?
    Thanks in advance!

    Hello,
    If you go into the "Subscription" in the Notifications section of the Operations Console\Administration, you should be able to see the Description of the subscription criteria.  Could you copy paste that in a reply?
    Thanks,
    Kris
    www.operatingquadrant.com

  • Error in identifying control File  , check alert for more details

    Hi ,
    I am unable to create user in the database , I can connect to sqlplus as sysdba
    Getting the following error :
    Error in identifying , check alert for more details :
    When I run : Show Parameter Contol_Files ;
    I am getting control01.ctl and control02.ctl with their paths mentioned.
    Kindly Help .

    1> env |sort
    COLORTERM=gnome-terminal
    CVS_RSH=ssh
    DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-YFSE8cCveS,guid=1736156c077604e0df1154004fe9c3bb
    DESKTOP_SESSION=default
    DESKTOP_STARTUP_ID=
    DISPLAY=:0.0
    G_BROKEN_FILENAMES=1
    GDMSESSION=default
    GDM_XSERVER_LOCATION=local
    GNOME_DESKTOP_SESSION_ID=Default
    GNOME_KEYRING_SOCKET=/tmp/keyring-C6CnCJ/socket
    GTK_RC_FILES=/etc/gtk/gtkrc:/home/oracle/.gtkrc-1.2-gnome2
    HISTSIZE=1000
    HOME=/home/oracle
    HOSTNAME=localhost.localdomain
    INPUTRC=/etc/inputrc
    KDEDIR=/usr
    KDE_IS_PRELINKED=1
    KDE_NO_IPV6=1
    LANG=en_US.UTF-8
    LESSOPEN=|/usr/bin/lesspipe.sh %s
    LOGNAME=oracle
    LS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:
    MAIL=/var/spool/mail/oracle
    OLDPWD=/home/oracle
    ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_1
    ORACLE_SID=ORCL
    PATH=/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/oracle/bin:/home/oracle/app/oracle/product/11.2.0/dbhome_1/bin
    PWD=/home/oracle/app/oracle/product/11.2.0
    SESSION_MANAGER=local/localhost.localdomain:/tmp/.ICE-unix/12103
    SHELL=/bin/bash
    SHLVL=2
    SSH_AGENT_PID=12142
    SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
    SSH_AUTH_SOCK=/tmp/ssh-IPvxh12103/agent.12103
    TERM=xterm
    USERNAME=oracle
    USER=oracle
    _=/usr/bin/env
    WINDOWID=26243546
    XAUTHORITY=/tmp/.gdmAO4NGW
    XMODIFIERS=@im=none
    2>Output of ls-l
    -rw-r----- 1 oracle oracle 9748480 Jun 30 00:53 /home/oracle/app/oracle/oradata/orcl/control01.ctl
    -rw-r----- 1 oracle oracle 9748480 Jun 30 00:53 /home/oracle/app/oracle/flash_recovery_area/orcl/control02.ctl
    3>
    SQL> show parameter control_files;
    NAME TYPE VALUE
    control_files string /home/oracle/app/oracle/oradat
    a/orcl/control01.ctl, /home/or
    acle/app/oracle/flash_recovery
    _area/orcl/control02.ctl
    4>
    SQL> startup
    ORACLE instance started.
    Total System Global Area 839282688 bytes
    Fixed Size 2217992 bytes
    Variable Size 494929912 bytes
    Database Buffers 339738624 bytes
    Redo Buffers 2396160 bytes
    ORA-00205: error in identifying control file, check alert log for more info
    I did by trying , startup upgrade , startup nomount
    but still facing the same error.
    Kindly help.

  • Alert for file not getting picked up

    Hi,
    how to create an alert when the file is not picked by adapter..consider a file adapterr...
    i mean the file is at the location...for some reasons the file is not being picked up....how to trigger an laert based on this.

    Aamir,
    its not an error...its just a requirement i need to fullfill.
    do you have any idea how to go ahead.......
    one more thing ..
    can you brief me what u said here....if file is not picked up due to some network connectivity issues and you get error in AE then alerts will be triggered
    u said only AE and IE errors are captured..then how about the above line u said....how will we trigger alerts...
    Edited by: Harsha reddy on Jun 24, 2008 8:03 PM

  • How to push data from primary mdf file to seconday ndf files

    how to push data from primary mdf file to seconday ndf files
    rathnakar

    I'd try them over here.
    SQL Server forums on MSDN
    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows]
    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.

  • SMS ALERT FOR FILE FAILURE

    Hi All,
        Most of the time the file prosessed in XI with high priority, so any processing error i got a mail but i need to implement the SMS alert for this, So as for quick responce. So what is the best way i can achive that.
    I have read most of the forum but this seems that i have to be a member for sending the mail as SMS, but is there any way i can achive this with free just by cnfiguring anythings.???
    Thanks in Advance,
    JAY

    hI,
    Alert Configuration
    http://help.sap.com/saphelp_nw04/helpdata/en/80/942f3ffed33d67e10000000a114084/frameset.htm
    Setting up alerts
    Setting up alerts in RZ20
    Alert Notification Step-by-Step
    http://help.sap.com/saphelp_nw04/helpdata/en/49/cbfb40f17af66fe10000000a1550b0/frameset.htm
    rEGARDS
    Edited by: Hari Kishore Gundala on Mar 11, 2008 10:48 AM

  • Restore MDF/LDF files

    We have a situation where someone deleted content of a table from the database. We have a backup of the MDF/LDF file where we can restore the database from - though we do not want to restore the entire database but only one table. I was thinking of creating
    a new database on the same SQL instance, restoring the mdf/ldf files to this newly created database and then import the information from the this database to the new db. How do I go about doing this using SQL server? Any help will be greatly appreciated. -RS

     
    Hi VJ Shah,
    If you are using SQL Server 2005 and higher, then we could use the Import and Export Wizard to copy the new table's data to the old one. Here are the general steps:
    Right click old database, select Tasks and then select Import Data…
    On the Choose a Data Source page, type your server name and select the new database, and then Next.
    On the Choose a Destination page, type your server name and select your old database, and then Next.
    On the Specify Table Copy or Query page, select Copy data from one or more tables or views, and the Next.
    On the Select Source Tables and Views, select the table which you want to copy, 
    specify the destination on the right column, and then Next.
    If there are any unclear, please feel free to ask.
    Thanks,
    Weilin Qiao
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. This can be beneficial to other community members reading the thread.

  • Silence Lenovo Solution Center Alerts for specific items via registry/config file.

    I need to be able to customize the alerts generated by LSC.  Like disabling alerts for updates and backups (I handle those for end users via other tools).  Is there a registry setting or file I can edit to change these alerts?  Requesting my end users open up LSC and disable specific alerts isn't an option.
    Thanks for any advice in advance!

    Hello everybody,
    I have set DECLINE_SECURITY_UPDATES=true but still have the problem.
    David D'Acquisto's response-files, don't help in my case because I need a completely silent installation with all necessary information inside. But his files are largely empty. So I can't figure out with entry in it causes the problem.
    Metalink contains the following "solution":
    "Cause
    The name of one environment variable contains spaces and the installer is not able to convert them internatelly. For instance, there is a variable called "PATH ".
    Bug 8995616 "DB INSTALLER VALIDATES EMAIL AND FAILS".
    Solution
    - Check the Environment variables and be sure that none contains spaces or special characters on its name
    - retry the installation
    I don't see any problem in my environment variables, or which ones should I check?
    Many thanks in advance,
    Xenofon

Maybe you are looking for

  • 9.3.1 Migration Utility gives "Project does not exists" error in log

    In preparation for using Hyperion Reporting and Analysis 9.3.1, I have installed the following on a Linux test server: --Oracle App Server 10.1.3 --Oracle Database 10g XE --Hyperion shared services 9.3.1 --Hyperion UI Services 9.3.1 --Hyperion SQR Pr

  • Over image not working in Nav Bar

    I have established Up and Over images for my nav bar. The Up image is all that shows -- even when I mouse-over or click on the button. Thanks for your help! Jim "MM_nbGroup('down','group1','WhatWeDo','Images_and_Video/WhatWeDo_Over.gif',1)" onmouseov

  • Delivery Completion Indicator on MIRO

    Does anyone know of a way to include the "Delivery Completed" Indicator u2013 ELIKZ from MEPO1313 in MIRO processing?  Our Accounts Payable staff would like to include the indicator check box on the MIRO layout. Thanks, -Patrick

  • Modifying customer

    Hello, Is it possible to modify the solld-to party number of a sales order? Thanks, Ricad.

  • Write to word document from oracle plsql

    Hi, Please provide methods to create and write to a word document from ORACLE PLSQL.We tried using UTL FILE package but it writes as ascii text.