I have a very small, non-essential database on my NAS that will be backed up weekly by a small Bash-script that is a modified version of this link's one:
outpath='/media/backupfiles/mysql_data'
dumpdate=$(date +"%Y-%m-%d")
mysqldump --user=xxx --password=xxx --events --all-databases | gzip -7 > ${outpath}/mysqldump_${dumpdate}.sql.gz
This script works flawlessly. However, I do not have much proficiency with Bash, while I love to code around with PowerShell. Naturally, I wanted to create an analog PowerShell-script:
param(
[string]$OutPath = "/media/backupfiles/mysql_data",
[string]$DumpBaseName = "mysqldump_$(Get-Date -Format "yyyy-MM-dd").sql"
)
mysqldump --user=xxx --password=xxx --events --all-databases | gzip -7 > $($OutPath)/$($DumpBaseName).gz
To start the script, I first started the console as root
, then started powershell
and then started the script /home/mysqldump.ps1
.
Unfortunately, the above script does not work:
out-file : Access to the path '/media/backupfiles/mysql_data' is denied.
When I enter
mysqldump --user=xxx --password=xxx --events --all-databases | gzip -7 > /media/backupfiles/mysql_data/test.sql.gz
in the console manually, the file will get produced, but it is too big (about twice the size of the Bash-version), has no user-privileges by itself (meaning I have to run chown
before I can access it), and also, when I then try to open it (with 7-zip or with gzip -d
), both tell me that the file can't be opened and that it is not in gzip format.
I then tried:
Start-Process mysqldump -ArgumentList " --user=xxx --password=xxx --events --all-databases | gzip -7 > /media/backupfiles/mysql_data/test.sql.gz"
This fails, too:
mysqldump: unknown option '-7'
To me, it seems like the pipe/redirection operator is the problem. Unfortunately, I do not have any more ideas as to how to make this script work (without intermediate-files or -scripts). The Internet did not prove very helpfull this time, however, that might be caused by me searching for the wrong things.
Is there anything that I am missing? Or am I simply trying to get a functionality that is not (yet) implemented in PowerShell for Linux?
Used software:
- OS: openmediavault 3.0.88 (which is Debian 4.9.30-2+deb9u2~bpo8+1 2017-06-27) x86_64 GNU/Linux)
- PowerShell: v6.0.0-beta.6
- gzip: 1.6
- mysqldump: Ver 10.13 Distrib 5.5.57