如何备份 SQL Server 2019 Express 并上传到 Azure Blob 并保留 120 天

How to backup SQL Server 2019 Express and upload to Azure Blob with 120 days retention

如何备份 SQL Server 2019 Express 并将其上传到保留天数的 Azure Blob?

  1. 下载AzCopy 8.1 and SqlPackage
  2. 使用下面的脚本添加命令

    cls
    forfiles /p "%CD%" /s /m *.* /D -120 /C "cmd /c del @FILE"
    echo -- BACKUP DATABASE --
    set DATABASENAME={Your db name}
    
    :: filename format Name-Date (eg MyDatabase-2009.5.19.bak)
    set DATESTAMP=%DATE:~-4%.%DATE:~7,2%.%DATE:~4,2%
    set BACKUPFILENAME=%CD%\%DATABASENAME%-%DATESTAMP%.bacpac
    echo.
    
    SqlPackage.exe /a:export /scs:"Server=(local);Database=%DATABASENAME%;Trusted_Connection=True;" /tf:"%BACKUPFILENAME%"
    
    
    AzCopy /Source:%BACKUPFILENAME% /Dest:https://myseogenie.blob.core.windows.net/db-bacup/%BACKUPFILENAME% /DestKey:{YOUR_KEY_HERE}/Y
    
    
    echo -- BACKUP DONE--
    
  3. 您可以创建一个 Windows 调度程序以每天 运行 它