How to backup more than one database using powershell

I am Trying to backup more than one database using the following script but no luck. I want user to type on command line the database they want to backup, e.g all databases that have "test" at the front like test.inventory, test.sales so i want
user to type test.* and it backs up all databases related to test. Here is the script
    #$date = Get-Date -Format yyyyMMddHHmmss
    #$dbname = 'test.inventory'
    $dbToBackup = "test.inventory"
    cls
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended") | 
    Out-Null
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo") 
    | Out-Null
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoEnum") | Out-
    Null
    Add-Type -AssemblyName "Microsoft.SqlServer.Smo, Version=10.0.0.0, Culture=neutral,   
    PublicKeyToken=89845dcd8080cc91"
    $server = New-Object Microsoft.SqlServer.Management.Smo.Server($env:ComputerName) 
    $server.Properties["BackupDirectory"].Value = "C:\_DBbackups"
    $server.Alter()
    $backupDirectory = $server.Settings.BackupDirectory
    #display default backup directory
    "Default Backup Directory: " + $backupDirectory
    $db = $server.Databases[$dbToBackup]
    $dbName = $db.Name
    $timestamp = Get-Date -format yyyyMMddHHmmss
    $smoBackup = New-Object ("Microsoft.SqlServer.Management.Smo.Backup")
    #BackupActionType specifies the type of backup.
    #Options are Database, Files, Log
    #This belongs in Microsoft.SqlServer.SmoExtended assembly
    $smoBackup.Action = "Database"
    $smoBackup.BackupSetDescription = "Full Backup of " + $dbName
    $smoBackup.BackupSetName = $dbName + " Backup"
    $smoBackup.Database = $dbName
    $smoBackup.MediaDescription = "Disk"
    $smoBackup.Devices.AddDevice($backupDirectory + "\" + $dbName + "_" + $timestamp +   
    ".bak", "File")
    $smoBackup.SqlBackup($server)
    #let's confirm, let's list list all backup files
    $directory = Get-ChildItem $backupDirectory
    $backupFilesList = $directory | where {$_.extension -eq ".bak"}
    $backupFilesList | Format-Table Name, LastWriteTime

Or i am using this script which backs up everything except tempdb but dont know how to modify this so that it backs up up all test related databases
Is there a way that i use test.*
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | out-null
$s = new-object ("Microsoft.SqlServer.Management.Smo.Server") $instance
$bkdir = "C:\_DBbackups" #We define the folder path as a variable 
$dbs = $s.Databases
foreach ($db in $dbs) 
     if($db.Name -ne "tempdb") #We don't want to backup the tempdb database 
     $dbname = $db.Name
     $dt = get-date -format yyyyMMddHHmm #We use this to create a file name based on the timestamp
     $dbBackup = new-object ("Microsoft.SqlServer.Management.Smo.Backup")
     $dbBackup.Action = "Database"
     $dbBackup.Database = $dbname
     $dbBackup.Devices.AddDevice($bkdir + "\" + $dbname + "_db_" + $dt + ".bak", "File")
     $dbBackup.SqlBackup($s)

Similar Messages

  • Can i backup more than one iphone using itunes on pc

    can i backup more than one iphone using itunes on pc

    Yes. It ought not to matter, but make sure you give each device a unique name.
    tt2

  • How to update more than one table using EO

    Hi frnds,
    Can someone provide me a doc/link which explain in detail how we can we update more than one PL/SQL tables using entity objects(on which VOs are based).
    Till date I have been doing this using PL/SQL procedures but now my requirement is to achieve it thru EO.Someone suggested me use VL to achieve plz help
    Thanks & Regards,

    Hi,
    That would be very nice of you,plz send me the docs and also send me similar docs that would be beneficial for a beginner like me.
    My id is [email protected]
    Thnx for your time.

  • How to pass more than one parameter using common...

    Hi,
    I am using ODP.NET with my 2005 VB
    I want to create function from where I can pass more than one parameter to execute SP, or query just like i created for SQL SERVER as below
    Public shared Function CreateParameter(ByVal paramname As String, ByVal paramvalue As Object) As DbParameter
    Dim param As DbParameter
    param = New SqlParameter
    param.ParameterName = paramname
    param.Value = paramvalue
    Return param
    End Function
    Public Shared Function ExecuteQuery(ByVal sql As String, ByVal commtype As CommandType, ByVal ParamArray parameter As DbParameter())
    Dim cmd As DbCommand = New SqlCommand()
    cmd.Connection = OpenConnection()
    cmd.CommandType = commtype
    cmd.CommandText = sql
    cmd.Parameters.AddRange(parameter)
    Dim RetVal As Integer = cmd.ExecuteNonQuery()
    Return RetVal
    End Function
    specially part is in bold to be converted
    I tried like but oracleCommand.parameters doesnt support AddRange
    please help me out
    Regards

    Hello,
    I used the following way:
    pCommand.CommandText = "Update " + sDataTable + " set "
    + sColumnName + " = :1 ";
    pCommand.Parameters.Add("ValueToDb",
    this.DefaultDbType,
    this.m_Value,
    System.Data.ParameterDirection.Input);
    Of course, you can add :2,... to your command text, too.
    The way back is:
    sEndOfTheClause += " RETURNING " + sDataTable + "." + sColName + " INTO :iNewValue";
    pCommand.CommandText = ... + sEndOfTheClause;
    pCommand.Parameters.Add("iNewValue", this.DefaultDbType,
    ParameterDirection.Output);
    bool bReturn = (pCommand.ExecuteNonQuery() != 0);
    if ((bReturn == true) && (pCommand.Parameters.Count > 0))
    this.Value = DataService.Convert<DATA_TYPE>(pCommand.Parameters[0].Value);
    ....

  • HT201269 How can I backup more than one device using itunes? Do I need 2 seperate itune accounts?

    please respond to question above

    Syncing and backing up in iTunes can be accomplished with multiple devices. They identify the devices based on the phone number, phone name, etc. The only way you would have an issue is if you were using different calendar contacts on the computer. http://support.apple.com/kb/ht1495

  • How to create more than one VIP use the same IP address and different port(e.g. 80 and 443)

    Hi,
    I use SCVMM LB Provider deploy network. I want to create 2 VIP use the same virtual IP but use the different port.
    for example:   VIP address 1.1.1.123   use port 80 for HTTP   and port 443 for HTTPS
    However,
    the following problems encountered, when I create the second VIP.
    PS C:\Windows\system32> New-SCLoadBalancerVIP -Name "vip11" -LoadBalancer $LB -IPAddress "1.1.1.123" -LoadBalancerVIPTemplate $VIPTemplate1 -LoadBalancerProtocol $Protocol1 -LoadBalancerHealthMonitor $HM1
    New-SCLoadBalancerVIP : A virtual IP (VIP) address with the specified name (vip11) or
    address (1.1.1.123) already exists on the load balancer (xxx). (Error ID: 13691)
    Specify a different name or IP address and try again.
    To restart the job, run the following command:
    PS> Restart-Job -Job (Get-VMMServer localhost | Get-Job | where { $_.ID -eq
    "{b41a77eb-ae0b-490a-8948-662a529b1d8c}"})
    At line:1 char:1
    + New-SCLoadBalancerVIP -Name "vip11" -LoadBalancer $LB -IPAddress "1.1.1.123" -Lo ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ReadError: (:) [New-SCLoadBalancerVIP], CarmineException
        + FullyQualifiedErrorId : 13691,Microsoft.SystemCenter.VirtualMachineManager.Cmdlets.Ne
       wSCLoadBalancerVIPCmdlet
    PS C:\Windows\system32>
    any suggestions ?
    Thank you in advance !

    I really don't know DDE very well. It is usually recommended that you switch to using ActiveX. You may not be correctly configuring the netDDE server. There is an example in the reource library that shows how to do this. You may also want to look at the DDE advise examples that came with LabVIEW 5.1 and earlier.

  • Can I use more than one database connections in a jdeveloper project?

    I use jdeveloper version 9.0.4.0 (build 1407),Can I use more than one database connections in one jdeveloper project?

    9.0.4 is a fairly old version, so you may only find a few people who know how it worked.
    Assuming you're using ADF BC, once known as BC4J, once know as JBO, in the project, and that the architecture hasn't changed much, then the answer is only 1 connection per project.
    Programmatically you're free to use as many connections via JEE as you see fit, but ADF BC is limited to one connection.
    CM.

  • How do u save datas more than one table using net beans ide using JSF

    Hi,
    I am new to JSF.
    I save / delete / update / New master table using POJO (Plain Old Java Objects), database - oracle and Toplink Persistence Unit.
    How do u save data more than one table using net beans ide using JSF (I am using POJO) ?
    and also Tell me the reference book for JSF.
    Thanks in advance.
    regards,
    N.P.Siva

    SivaNellai wrote:
    I am new to JSF.
    So, I am using net beans IDE 6.1 from sun microsystem. It is a free software.No, you don't drag'n'drop if you're new to JSF. Switch to source code mode. Write code manually, with the help of IDE for the speed up.
    So, please guide me the reference books, articles. I need the basic understanding of JSF, net beans IDE.[JSF: The Complete Reference|http://www.amazon.com/JavaServer-Faces-Complete-Reference/dp/0072262400] is a good book. The [JSF specification document|http://jcp.org/aboutJava/communityprocess/final/jsr252/index.html] is also a good reading to understand what JSF is and how it works. There are also javadocs and tlddocs of Sun JSF Mojarra.

  • How can i connect more  than one database

    i would like to connect more than one database one my laptop
    now i have database one and sid=ddms
    and i would another such as sid=ddmf
    how can i connect two database on the same my laptop

    I am not sure what you mean by after built? Are you trying to export data from one database and import it into another? If so, export it using data pump making sure you have the correct ORACLE_SID. Also be sure both database have to same character set. Then change the ORACLE_SID to other database, and run data pump to import the data into the other database. Hope that makes any sense...

  • How to configure EM Grid Control for more than one databases?

    Hi,
    I'm configuring EM on Oracle 10gRel1 on Linux. I have more than one databases in the server, and I want use IE at my PC to monitor the databases on Linux server. I can configure and access the Grid Control Console by emca for first database, but cannot configure for the second one, unless I remove the first one configurration. How can I configure EM for more than one databases?
    Thanks.

    Thank you everybody.
    Yes, I'm talking about DBConsole rather than Grid Control (sorry for misuse the term). I managed to set up DB Console for every DB in the same Linux box (10Rel1). What I did is:
    1) stop db console and agent with emctl
    2) remove repository with RepManager
    3) config with emca
    Then I can monitor individual databases from my PC (but have to login with different port).
    I'm thinking mybe I should use Grid Control instead.

  • How to configure html db on more than one database

    Hi
    how can we configure one html db on more than one database.
    I have tried to configure the DAD.conf file. Also i have tried to do it by virtual hosting.
    can anyone mail a DAD.conf file.
    Ahanks
    Ameya

    This is easy and the internet is full of examples. Here is what I used (replace the strings in ## with your values):
    CREATE LINK STATEMENT:
    create database link #YOUR_LINK_NAME#
    connect to #USER_WITH_REQUIRED_ROLES_ON_REMOTE_DB# identified by #USER_PASSWORD#
    using ' #TNS_NAMES_ENTRY_FOR_THAT_CONNECTION#';
    ALTERNATIVELY:
    create database link #YOUR_LINK_NAME#
    connect to #USER_WITH_REQUIRED_ROLES_ON_REMOTE_DB# identified by #USER_PASSWORD#
    using '(DESCRIPTION =
    (ADDRESS = (PROTOCOL = tcp)(HOST = #YOUR_HOST#)(PORT = 1531))
    (CONNECT_DATA =
    (SID = #YOUR_TNS_SID#)
    After creating a link you reference the tables using the following syntax:
    table_name@link_name
    Denes Kubicek

  • How to make more than one person can access the database at one time

    how to make  more than one person can access the database at one time 

    Please post further f'up's in the Access forum.
    In short: for different reasons it is best practice that each user gets its own local copy of the database. This means that you need to split it into a front-end which only consists of the forms, queries, reports etc. Everything which doesn't need to be
    shared. And a back-end, which only stores the data.
    Take also a look at Allen Browne's article:
    Split your Access database into data and application.
    When you've splitted your database, you may often consider to use SQL Server as back-end. Here you may read Armen Stein's
    The Best of Both Worlds: Access-SQL Server Optimization.

  • More than one database driver has been used

    Hi everyone, I just want to link 2 tables, one in Oracle and the second is in Access, is this possible? Please help, tahnks a lot.
    I got this message:
    "More than one database driver has been used in this report. If you want to change the database drivers use Database/Set Location.
    Please make sure that no SQL Expression is added and no server-side group-by is performed"
    This is the query generated:
    SELECT "A"."Field_in_A"
    FROM   "OracleDB"."A" "A"
    SELECT `B`.`Field_in_B`
    FROM   `AccessDB` `B`

    The above suggestions are good. You might also consider using a link table from MS Access to have the linking done right inside MS Access. 
    If you can store your access mdb file on the server where your Oracle database resides this will greatly reduce your network traffic.  If the MS Access database must reside on a different machine it can still work but the gains won't be as great.  Still, this is an efficient way to do this if you can.
    To create a link table in MS Access choose, New, then 'Link Table'. In the Link dialog that appears you can choose ODBC.  I recommend using the SQORA driver from Oracle that is installed with SQL Plus.
    If you have to link in Crystal Reports instead you still can. However, all data from the Oracle table and Access table will be pulled to the client that hosts Crystal Reports and sorting will be done on the Crystal client.
    You definitely have some good options though.

  • How to install Runtime Platform for more than one database on one machine

    Hi,
    What the docs loosely call Runtime Platform Service is in my opinion a combination of
    A) a bunch of software (installed under an ORACLE_HOME)
    B) the actual service process
    My question: if I have more than one databases on one machine, each containing an OWB Runtime, am I correct in assuming that I have to install the Runtime Platform software only once, but there will be a separate service process running for each database, each adressing the same Runtime Platform software? So under ORACLE_HOME nothing is kept that refers to a particular database?
    Jaap.

    Yes, we use such a configuration on our site. We have one OWB ORACLE_HOME and uses up to 4 instances. Each instance has its own Runtime Service Process running.
    Regards, Silvio

  • How to pull groups from more than one OU using weblogic "All Groups Filter" from AD.

    Hi,
    Please help me for pulling groups from more than one OU using weblogic "All Groups Filter" from AD.
    AD structure is:
    c001639domain.local
           ||
           ||
        OU=Security_Groups
                      ||
                      ||
                      >> OU=CORP_ECM---> n number of group
                      >> OU=CORP_hodata--> n number of group
                      >> OU=CORP_citrix--> n number of group
                      >> OU=CORP_driver --> n number of group
                      >> OU=CORP_temp --> n number of group
    Requirement is i want to filter groups from OU=CORP_ECM and OU=CORP_hodata.
    Thanks,
    Jagan.

    I used below option but its not working getting zero groups.
    (&(objectClass=group)(|(ou=CORP_ECM,dc=Domain,dc=com)(ou=CORP_hodata,dc=c001639domain,dc=local)))

Maybe you are looking for

  • File sender adapter: trigger mail if file is not there

    Hi, I have an scenario where I have a file sender adapter, and I need to look for a file in a specific folder from a specific FTP site. If the file is not present there, I need to trigger an alert to let some people know that the file was not found.

  • Outlook 2010 corrupting incoming pdf attachments for one user

    I have one user here that is having incoming pdf attachments get corrupted in Outlook 2010. When she tries to open the file, it gives the error "Adobe Reader could not open filename.pdf because it is either not a supported file type or because the fi

  • No T-Code in SAP can damage your data, all t-code has initial screens?

    As per my understanding there is no SAP standard t-code in SAP which can damage SAP or data in database when you run from SAPGUI (do not execute once you are in t-code). What's your thinking?

  • IP Address of Client after IISProxy.dll configured

    Hi, We have a requirement to capture IP address of client. we are able to do it when the users access the portal from inside the firewall using portal url. http://<servername>:port/irj but when users access the portal outside the firewall we have IIS

  • Advice for Zooming

    Hello! I need some advice about something I want to implement in one of my applications, Zooming. Basically, I have a large picture that should act like a map (for example) and the user can only see part of it at one time, so I need to implement Zoom