3 ms·
> I'm not understanding what you're meaning here. If this was PowerShell then I would just get the list of files in $PGDATA, create folders and then move the
by justsomehnguy 3y ago
> I'm not understanding what you're meaning here.
If this was PowerShell then I would just get the list of files in $PGDATA, create folders and then move the files in the list, ie
$files = gci $PGDATA
try {
New-item "$PGDATA/old" -erroraction stop
New-item "$PGDATA/new" -erroraction stop
}
catch {
throw "Failed to create the necessary dirs"
}
try {
$files | Move-Item -Destination "$PGDATA/old" -erroraction stop
}
catch {
# throw "Failed to move pg_data, your databases are now borked, good luck"
gci "$PGDATA/new" | move-item $PGDATA
}
It's way more streamlined and if creating the dirs would fail (especially `new`) then it would fail before moving the data. And you don't need to `set +e` in this part.
I tried to replicate this in Linux and... it's a mess.
`find` includes the directory in the list, `ls -1` does the thing but bash stores it's output as a single string, redirecting it to the file get this file included in the list... I even tried xargs, but quickly abandoned the idea. Though if you can create the redirected output file in some other place than $PGDATA (`/tmp` perharps?) then `ls -1` trick would work.
- justinclift 3y ago> "Failed to move pg_data, your databases are now borked, good luck" :D --- Oh. Now I understand the purpose of grabbing a file list first. That would allow for creating both old + new dirs first, prior to any move attempt. I'll think it over. I'm kind of on the fence about it at first though. Lets see what I reckon after sleeping on it. Thanks for following up btw. :)