Skip to main content

[PowerShell]: Powershell script uploading backup databases to ftp server

Author: Enrique Puig Nouselles
http://gallery.technet.microsoft.com/scriptcenter/80647f66-139c-40a4-bb7a-04a2d73d423c


Nhu cầu
- Học sử dụng Powershell và áp dụng vào thực tế
- Server chạy MS SQL được backup mỗi ngày và lưu các file backup ở folder mặc định "C:/Program Files/Microsoft SQL Server/MSSQL11.MSSQLSERVER/MSSQL/Backup"
- Upload các file database backup về một ftp server khác để lưu "offsite"

# Begin script
# Thanks to: Enrique Puig Nouselles http://gallery.technet.microsoft.com/scriptcenter/80647f66-139c-40a4-bb7a-04a2d73d423c
# Khai báo folder chứa các file backup database, dưới đây là folder backup mặc định của MS SQL 2012
$Dir="C:/Program Files/Microsoft SQL Server/MSSQL11.MSSQLSERVER/MSSQL/Backup"  

# ftp server
$ftp = "ftp://IPAddres/subfolder/subsubfolder"
$user = "usernamehere"
$pass = "passwordhere"
# DO NOT use $(Get-Date), use $d variable instead, otherwise SQL Agent gets error "The job step contains tokens...."
$d = Get-Date

$webclient = New-Object System.Net.WebClient

$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)

# Get files created in the past 24 hours
#list every sql server trace file
foreach($item in (dir $Dir "*.bak")){
if ($item.CreationTime -gt ($d.AddDays(-1)))
{
    "Uploading $item..."
    $uri = New-Object System.Uri($ftp+$item.Name)
    $webclient.UploadFile($uri, $item.FullName)
} }
#End

Popular posts from this blog

hmailserver: Notes from the field

hmailserver is one of free open source mail servers running on Microsoft Windows operating system.

stegseek: Notes

StegCracker has been retired following the release of StegSeek, which will blast through the rockyou.txt wordlist within 1.9 second as opposed to StegCracker which takes ~5 hours.

VMware ESXi host loads ipmi_si_drv too long

Workaround: remove ipmi_si_drv esxcli software vib remove --dry-run --vibname ipmi-ipmi-si-drv esxcli software vib remove --vibname ipmi-ipmi-si-drv ~ # esxcli software vib remove --dry-run --vibname ipmi-ipmi-si-drv Removal Result    Message: Dryrun only, host not changed. The following installers will be applied: [BootBankInstaller]    Reboot Required: true    VIBs Installed:    VIBs Removed: VMware_bootbank_ipmi-ipmi-si-drv_39.1-4vmw.550.0.0.1331820    VIBs Skipped: ~ # ~ # esxcli software vib remove --vibname ipmi-ipmi-si-drv Removal Result    Message: The update completed successfully, but the system needs to be rebooted for the changes to be effective.    Reboot Required: true    VIBs Installed:    VIBs Removed: VMware_bootbank_ipmi-ipmi-si-drv_39.1-4vmw.550.0.0.1331820    VIBs Skipped: ~ #