VeeamHub / veeam-ansible

Sample code for deploying and configuring various Veeam solutions using Ansible.
GNU Lesser General Public License v3.0
47 stars 18 forks source link

When database is not installed locally, consider another mechanism to trigger DB backup #28

Closed rnickle closed 2 years ago

rnickle commented 2 years ago

Is your feature request related to a problem? Please describe.

Pertinent Code:

- name: Start adhoc EM database backup to default SQL backup location
  ansible.windows.win_shell: |
    $secureString = ConvertTo-SecureString "{{ sql_password }}" -AsPlainText -Force
    $credential = New-Object System.Management.Automation.PSCredential ("{{ sql_username }}", $secureString)
    Backup-SqlDatabase -ServerInstance "{{ sql_instance }}" -Database "{{ sql_database }}" -Credential $credential
  no_log: true

Pertinent Error:

PS C:\windows\system32> Backup-SqlDatabase
Backup-SqlDatabase : The term 'Backup-SqlDatabase' is not recognized as the
name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is
correct and try again.
At line:1 char:1
+ Backup-SqlDatabase
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Backup-SqlDatabase:String) [],
   CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Describe the solution you'd like I wonder if perhaps this should be configurable, perhaps there's a way to trigger the backup remotely (we rely on our DBA team to do the backups), or perhaps we can prompt the user to let them know that an SQL backup is advised but not possible with this set of tools?

Describe alternatives you've considered Making this step configurable with a parameter defined in group_vars.

Additional context I'm not sure how to trigger this remotely, I will seek advice from the DBA team.

Thank you!

carceneaux commented 2 years ago

Can you please clarify which task file you're referencing?

If you're upgrading EM server, the cmdlet should've been installed prior to running it in this line. If this install failed, it would result in the behavior you've outlined.

https://github.com/VeeamHub/veeam-ansible/blob/master/roles/veeam_vas/tasks/em_upgrade.yml#L74

rnickle commented 2 years ago

Good point, I'm sorry I didn't mention that in my issue. I was using the vbr_upgrade,a and It didn't occur to me that I should've upgraded EM first then VBR until I ran into this error. I went to do a test run via the manual upgrade process to see if that would give me clues, and that prompted me to retry with the em_upgrade first. It did not install the cmdlet so I disabled this section.

I am willing to recreate the steps, including reverting to a snapshot to try it from scratch.

carceneaux commented 2 years ago

Yeah, I'll need more info to determine where the issue lies. I just deployed a fresh Server 2019 OS and the PowerShell module installed and functioned correctly.

The only reason I can think of the module wouldn't have installed is if you left the default sql_instance specified. As I believe your SQL server is remote, this shouldn't have been the case.

rnickle commented 2 years ago

Windows Server 2019 Standard, Version 1809, build 17763.2452 (probably the same thing you're running I would imagine.)

Now, for the SQL server, the DBA team offered us an option to try out using an instance hosted on MSSQL on Linux on a VM in their environment. We tried this out on our "pilot" environment, the one I'm testing here. In formal development and formal production, we're using a regular MSSQL instance on what I believe is a regular SQL Server 2019 Standard.

I wonder if maybe it is because I didn't quote my sql_database: setting?

So I used the header from a fresh copy of your EM playbook, and just marked it up a little:

---
- name: Veeam Enterprise Manager Upgrade 11A
  hosts: windows_veeam
  gather_facts: yes
  tasks:
    - include_role:
        name: veeamhub.veeam.veeam_vas
        tasks_from: em_upgrade
      vars:
        version: "11"
        iso_download: false
        license: true
        destination_iso_file: "VeeamBR_11.0.1.1261_20211211.iso"
        destination: "C:\\windows\\temp\\"
        sql_username: "redacted_sa"
        sql_database: devdatabase
        source_license: "/home/redacted/license.lic"

It might be that simple. Is it okay to use a PB like this to just override your vars?

carceneaux commented 2 years ago

Yep, that's the purpose of specifying the vars here is to override the defaults so the install/upgrade is specific to your environment.

Looking at your sample, you're missing the following variables:

If sql_instance isn't specified, the default is used which skips the installation of the PowerShell module. I believe this to be the source of your issue. As such, I'm going to close this out. If you believe this not to be the case, please feel free to re-open.