Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

(sin asunto)

1 mensaje
Omar E. Vsquez Chavarri <omar.vasquez.chavarri@gmail.com>
Para: Omar Eduardo Vasquez Chavarri <omar.vasquez.chavarri@gmail.com>

mar., ago. 30, 2016 a la hora 20:08

#Backup
script for
Wordpress
installation
#Dependencies: Powershell 2.0+ (required) 7zip (optional), SMTP server without authentication
(optional)
#Author: Tobias Jrvelv - @jarvelov
#Author homepage: tobias.jarvelov.se
#Last updated: 2016-03-02
## Config Start ##
#Credentials
$mysqlUser = "user"

#Mysql username

$mysqlPass = "pass"

#Mysql password

$mysqlHost = "localhost" #omit quotes if using IP


$mysqlDatabase = "mydb" #Name database you want to export
$mysqlCharset = "utf8"

#Change this if your server is not using UTF8 encoding

#Filepaths
$sourceDir = "WPINSTALLDIR"

#e.g. C:\inetpub\wwwroot

$destDir = "ZIPDESTINATIONDIR" #e.g. D:\Backup


$sqlOutputFile = "mydb.sql"

#Output filename for dumped database (will be placed in root of

the zip file)


$mysqlDump = "mysqldump.exe"

#If mysqldump.exe not in PATH use format '"C:\Program

Files\MySQL\MySQL Server 5.7\bin\mysqldump.exe"'


$7zip = "7za.exe"

#if 7za.exe not in PATH use format '"C:\Program

Files\7zip\7za.exe"'
#Settings
$mailEnabled = $True

#Set to $False if you don't want an email

$zipEnabled = $True

#Set to $False if you don't want to compress the directory and

just move it to the destination directory ($destDir)


#Mail settings
$subject = "WP backup - "
$recipients = "user@example.com"
$sender = 'WP backup <user@example.com>'
#Smtp settings
$smtpServer = "localhost"

#Must be an SMTP server WITHOUT authentication

$smtpPort = 25
#Output directory name format
$prefix = "wpbackup_"
$date = (Get-Date -Format "yyyy_MM_dd_HHmm").ToString()

## Config End ##
#No need to configure anything below this line"
## Functions ##
Function Write-Log ($msg){
$logDate = (Get-Date -Format "yyyy_MM_dd_HHmm").ToString()
$content = "$logDate : $msg"
Write-Host $content
Add-Content -Value $content -Path $logFile
}
## Program Start ##
#Create log and temporary folder
$name = "Create folders"
$logDir =".\logs\"
$logFile = "$logDir$prefix$date.txt"
$tmpName = "$prefix$date"
$tmpDir = ".\$tmpName"
$steps = @()
Try {
If((Test-Path ($logDir)) -eq $false) {
New-Item -ItemType Directory -Path $logDir | Out-Null
}
Write-Log "Info $name : Creating log and temporary directories."
#Make sure $tmpDir exists
If((Test-Path ($tmpDir)) -eq $false) {
New-Item -ItemType Directory -Path $tmpDir | Out-Null
}
#Make sure $destDir exists
If((Test-Path ($destDir)) -eq $false) {
New-Item -ItemType Directory -Path $destDir | Out-Null
}
$status = $true
} Catch [Exception] {
Write-Log "Failure $name : Could not create temporary directories. Exception:
"$_.Exception.Message
$status = $false
}
$steps += @($status,$name)
#Copy Wordpress installation
$name = "Copy files"
Write-Log "Info $name : Copying Wordpress directory..."
Try {
Copy-Item -Path $sourceDir -Recurse -Destination "$tmpDir"
#If copy is done but tmpDir isn't created, report failure

If((Test-Path ($tmpDir)) -eq $false) {


Write-Log "Failure $name : Path $tmpDir does not exist"

...

You might also like