mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-04 07:22:34 +00:00
Merge (#127)
This commit is contained in:
146
app/SSH/Services/Database/AbstractDatabase.php
Executable file
146
app/SSH/Services/Database/AbstractDatabase.php
Executable file
@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace App\SSH\Services\Database;
|
||||
|
||||
use App\Models\BackupFile;
|
||||
use App\Models\Server;
|
||||
use App\Models\Service;
|
||||
use App\SSH\HasScripts;
|
||||
use App\SSH\Services\ServiceInterface;
|
||||
|
||||
abstract class AbstractDatabase implements Database, ServiceInterface
|
||||
{
|
||||
use HasScripts;
|
||||
|
||||
protected Service $service;
|
||||
|
||||
protected Server $server;
|
||||
|
||||
abstract protected function getScriptsDir(): string;
|
||||
|
||||
public function __construct(Service $service)
|
||||
{
|
||||
$this->service = $service;
|
||||
$this->server = $service->server;
|
||||
}
|
||||
|
||||
public function install(): void
|
||||
{
|
||||
$version = $this->service->version;
|
||||
$command = $this->getScript($this->service->name.'/install-'.$version.'.sh');
|
||||
$this->server->ssh()->exec($command, 'install-'.$this->service->name.'-'.$version);
|
||||
$status = $this->server->systemd()->status($this->service->unit);
|
||||
$this->service->validateInstall($status);
|
||||
}
|
||||
|
||||
public function create(string $name): void
|
||||
{
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript($this->getScriptsDir().'/create.sh', [
|
||||
'name' => $name,
|
||||
]),
|
||||
'create-database'
|
||||
);
|
||||
}
|
||||
|
||||
public function delete(string $name): void
|
||||
{
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript($this->getScriptsDir().'/delete.sh', [
|
||||
'name' => $name,
|
||||
]),
|
||||
'delete-database'
|
||||
);
|
||||
}
|
||||
|
||||
public function createUser(string $username, string $password, string $host): void
|
||||
{
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript($this->getScriptsDir().'/create-user.sh', [
|
||||
'username' => $username,
|
||||
'password' => $password,
|
||||
'host' => $host,
|
||||
]),
|
||||
'create-user'
|
||||
);
|
||||
}
|
||||
|
||||
public function deleteUser(string $username, string $host): void
|
||||
{
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript($this->getScriptsDir().'/delete-user.sh', [
|
||||
'username' => $username,
|
||||
'host' => $host,
|
||||
]),
|
||||
'delete-user'
|
||||
);
|
||||
}
|
||||
|
||||
public function link(string $username, string $host, array $databases): void
|
||||
{
|
||||
$ssh = $this->server->ssh();
|
||||
|
||||
foreach ($databases as $database) {
|
||||
$ssh->exec(
|
||||
$this->getScript($this->getScriptsDir().'/link.sh', [
|
||||
'username' => $username,
|
||||
'host' => $host,
|
||||
'database' => $database,
|
||||
]),
|
||||
'link-user-to-database'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function unlink(string $username, string $host): void
|
||||
{
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript($this->getScriptsDir().'/unlink.sh', [
|
||||
'username' => $username,
|
||||
'host' => $host,
|
||||
]),
|
||||
'unlink-user-from-databases'
|
||||
);
|
||||
}
|
||||
|
||||
public function runBackup(BackupFile $backupFile): void
|
||||
{
|
||||
// backup
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript($this->getScriptsDir().'/backup.sh', [
|
||||
'file' => $backupFile->name,
|
||||
'database' => $backupFile->backup->database->name,
|
||||
]),
|
||||
'backup-database'
|
||||
);
|
||||
|
||||
// upload to storage
|
||||
$upload = $backupFile->backup->storage->provider()->ssh($this->server)->upload(
|
||||
$backupFile->path(),
|
||||
$backupFile->storagePath(),
|
||||
);
|
||||
|
||||
// cleanup
|
||||
$this->server->ssh()->exec('rm '.$backupFile->name.'.zip');
|
||||
|
||||
$backupFile->size = $upload['size'];
|
||||
$backupFile->save();
|
||||
}
|
||||
|
||||
public function restoreBackup(BackupFile $backupFile, string $database): void
|
||||
{
|
||||
// download
|
||||
$backupFile->backup->storage->provider()->ssh($this->server)->download(
|
||||
$backupFile->storagePath(),
|
||||
$backupFile->name.'.zip',
|
||||
);
|
||||
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript($this->getScriptsDir().'/restore.sh', [
|
||||
'database' => $database,
|
||||
'file' => $backupFile->name,
|
||||
]),
|
||||
'restore-database'
|
||||
);
|
||||
}
|
||||
}
|
24
app/SSH/Services/Database/Database.php
Executable file
24
app/SSH/Services/Database/Database.php
Executable file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\SSH\Services\Database;
|
||||
|
||||
use App\Models\BackupFile;
|
||||
|
||||
interface Database
|
||||
{
|
||||
public function create(string $name): void;
|
||||
|
||||
public function delete(string $name): void;
|
||||
|
||||
public function createUser(string $username, string $password, string $host): void;
|
||||
|
||||
public function deleteUser(string $username, string $host): void;
|
||||
|
||||
public function link(string $username, string $host, array $databases): void;
|
||||
|
||||
public function unlink(string $username, string $host): void;
|
||||
|
||||
public function runBackup(BackupFile $backupFile): void;
|
||||
|
||||
public function restoreBackup(BackupFile $backupFile, string $database): void;
|
||||
}
|
11
app/SSH/Services/Database/Mariadb.php
Normal file
11
app/SSH/Services/Database/Mariadb.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\SSH\Services\Database;
|
||||
|
||||
class Mariadb extends AbstractDatabase
|
||||
{
|
||||
protected function getScriptsDir(): string
|
||||
{
|
||||
return 'mysql';
|
||||
}
|
||||
}
|
11
app/SSH/Services/Database/Mysql.php
Executable file
11
app/SSH/Services/Database/Mysql.php
Executable file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\SSH\Services\Database;
|
||||
|
||||
class Mysql extends AbstractDatabase
|
||||
{
|
||||
protected function getScriptsDir(): string
|
||||
{
|
||||
return 'mysql';
|
||||
}
|
||||
}
|
11
app/SSH/Services/Database/Postgresql.php
Normal file
11
app/SSH/Services/Database/Postgresql.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\SSH\Services\Database;
|
||||
|
||||
class Postgresql extends AbstractDatabase
|
||||
{
|
||||
protected function getScriptsDir(): string
|
||||
{
|
||||
return 'postgresql';
|
||||
}
|
||||
}
|
12
app/SSH/Services/Database/scripts/mariadb/install-10.3.sh
Executable file
12
app/SSH/Services/Database/scripts/mariadb/install-10.3.sh
Executable file
@ -0,0 +1,12 @@
|
||||
wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
|
||||
|
||||
chmod +x mariadb_repo_setup
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive ./mariadb_repo_setup \
|
||||
--mariadb-server-version="mariadb-10.3"
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get update
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get install mariadb-server mariadb-backup -y
|
||||
|
||||
sudo service mysql start
|
12
app/SSH/Services/Database/scripts/mariadb/install-10.4.sh
Executable file
12
app/SSH/Services/Database/scripts/mariadb/install-10.4.sh
Executable file
@ -0,0 +1,12 @@
|
||||
wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
|
||||
|
||||
chmod +x mariadb_repo_setup
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive ./mariadb_repo_setup \
|
||||
--mariadb-server-version="mariadb-10.4"
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get update
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get install mariadb-server mariadb-backup -y
|
||||
|
||||
sudo service mysql start
|
11
app/SSH/Services/Database/scripts/mysql/backup.sh
Normal file
11
app/SSH/Services/Database/scripts/mysql/backup.sh
Normal file
@ -0,0 +1,11 @@
|
||||
if ! sudo DEBIAN_FRONTEND=noninteractive mysqldump -u root __database__ > __file__.sql; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! DEBIAN_FRONTEND=noninteractive zip __file__.zip __file__.sql; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! rm __file__.sql; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
9
app/SSH/Services/Database/scripts/mysql/create-user.sh
Executable file
9
app/SSH/Services/Database/scripts/mysql/create-user.sh
Executable file
@ -0,0 +1,9 @@
|
||||
if ! sudo mysql -e "CREATE USER IF NOT EXISTS '__username__'@'__host__' IDENTIFIED BY '__password__'"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo mysql -e "FLUSH PRIVILEGES"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
echo "Command executed"
|
5
app/SSH/Services/Database/scripts/mysql/create.sh
Executable file
5
app/SSH/Services/Database/scripts/mysql/create.sh
Executable file
@ -0,0 +1,5 @@
|
||||
if ! sudo mysql -e "CREATE DATABASE IF NOT EXISTS __name__ CHARACTER SET utf8 COLLATE utf8_general_ci"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
echo "Command executed"
|
9
app/SSH/Services/Database/scripts/mysql/delete-user.sh
Executable file
9
app/SSH/Services/Database/scripts/mysql/delete-user.sh
Executable file
@ -0,0 +1,9 @@
|
||||
if ! sudo mysql -e "DROP USER IF EXISTS '__username__'@'__host__'"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo mysql -e "FLUSH PRIVILEGES"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
echo "Command executed"
|
5
app/SSH/Services/Database/scripts/mysql/delete.sh
Executable file
5
app/SSH/Services/Database/scripts/mysql/delete.sh
Executable file
@ -0,0 +1,5 @@
|
||||
if ! sudo mysql -e "DROP DATABASE IF EXISTS __name__"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
echo "Command executed"
|
13
app/SSH/Services/Database/scripts/mysql/install-5.7.sh
Executable file
13
app/SSH/Services/Database/scripts/mysql/install-5.7.sh
Executable file
@ -0,0 +1,13 @@
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get install mysql-server -y
|
||||
|
||||
sudo service mysql enable
|
||||
|
||||
sudo service mysql start
|
||||
|
||||
if ! sudo mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH auth_socket;"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo mysql -e "FLUSH PRIVILEGES"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
19
app/SSH/Services/Database/scripts/mysql/install-8.0.sh
Executable file
19
app/SSH/Services/Database/scripts/mysql/install-8.0.sh
Executable file
@ -0,0 +1,19 @@
|
||||
wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive dpkg -i mysql-apt-config_0.8.22-1_all.deb
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get update
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get install mysql-server -y
|
||||
|
||||
sudo service mysql enable
|
||||
|
||||
sudo service mysql start
|
||||
|
||||
if ! sudo mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH auth_socket;"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo mysql -e "FLUSH PRIVILEGES"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
9
app/SSH/Services/Database/scripts/mysql/link.sh
Executable file
9
app/SSH/Services/Database/scripts/mysql/link.sh
Executable file
@ -0,0 +1,9 @@
|
||||
if ! sudo mysql -e "GRANT ALL PRIVILEGES ON __database__.* TO '__username__'@'__host__'"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo mysql -e "FLUSH PRIVILEGES"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
echo "Linking to __database__ finished"
|
11
app/SSH/Services/Database/scripts/mysql/restore.sh
Normal file
11
app/SSH/Services/Database/scripts/mysql/restore.sh
Normal file
@ -0,0 +1,11 @@
|
||||
if ! DEBIAN_FRONTEND=noninteractive unzip __file__.zip; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo DEBIAN_FRONTEND=noninteractive mysql -u root __database__ < __file__.sql; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! rm __file__.sql __file__.zip; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
5
app/SSH/Services/Database/scripts/mysql/unlink.sh
Executable file
5
app/SSH/Services/Database/scripts/mysql/unlink.sh
Executable file
@ -0,0 +1,5 @@
|
||||
if ! sudo mysql -e "REVOKE ALL PRIVILEGES, GRANT OPTION FROM '__username__'@'__host__'"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
echo "Command executed"
|
19
app/SSH/Services/Database/scripts/postgresql/backup.sh
Normal file
19
app/SSH/Services/Database/scripts/postgresql/backup.sh
Normal file
@ -0,0 +1,19 @@
|
||||
if ! sudo -u postgres pg_dump -d __database__ -f /var/lib/postgresql/__file__.sql; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo mv /var/lib/postgresql/__file__.sql /home/vito/__file__.sql; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo chown vito:vito /home/vito/__file__.sql; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! DEBIAN_FRONTEND=noninteractive zip __file__.zip __file__.sql; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! rm __file__.sql; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
5
app/SSH/Services/Database/scripts/postgresql/create-user.sh
Executable file
5
app/SSH/Services/Database/scripts/postgresql/create-user.sh
Executable file
@ -0,0 +1,5 @@
|
||||
if ! sudo -u postgres psql -c "CREATE ROLE __username__ WITH LOGIN PASSWORD '__password__';"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
echo "User __username__ created"
|
6
app/SSH/Services/Database/scripts/postgresql/create.sh
Normal file
6
app/SSH/Services/Database/scripts/postgresql/create.sh
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
if ! sudo -u postgres psql -c "CREATE DATABASE __name__"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
echo "Database __name__ created"
|
5
app/SSH/Services/Database/scripts/postgresql/delete-user.sh
Executable file
5
app/SSH/Services/Database/scripts/postgresql/delete-user.sh
Executable file
@ -0,0 +1,5 @@
|
||||
if ! sudo -u postgres psql -c "DROP USER __username__"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
echo "User __username__ deleted"
|
5
app/SSH/Services/Database/scripts/postgresql/delete.sh
Executable file
5
app/SSH/Services/Database/scripts/postgresql/delete.sh
Executable file
@ -0,0 +1,5 @@
|
||||
if ! sudo -u postgres psql -c "DROP DATABASE __name__"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
echo "Database __name__ deleted"
|
11
app/SSH/Services/Database/scripts/postgresql/install-12.sh
Normal file
11
app/SSH/Services/Database/scripts/postgresql/install-12.sh
Normal file
@ -0,0 +1,11 @@
|
||||
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
|
||||
|
||||
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get update -y
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get install postgresql-12 -y
|
||||
|
||||
systemctl status postgresql
|
||||
|
||||
sudo -u postgres psql -c "SELECT version();"
|
11
app/SSH/Services/Database/scripts/postgresql/install-13.sh
Normal file
11
app/SSH/Services/Database/scripts/postgresql/install-13.sh
Normal file
@ -0,0 +1,11 @@
|
||||
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
|
||||
|
||||
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get update -y
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get install postgresql-13 -y
|
||||
|
||||
systemctl status postgresql
|
||||
|
||||
sudo -u postgres psql -c "SELECT version();"
|
11
app/SSH/Services/Database/scripts/postgresql/install-14.sh
Normal file
11
app/SSH/Services/Database/scripts/postgresql/install-14.sh
Normal file
@ -0,0 +1,11 @@
|
||||
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
|
||||
|
||||
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get update -y
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get install postgresql-14 -y
|
||||
|
||||
systemctl status postgresql
|
||||
|
||||
sudo -u postgres psql -c "SELECT version();"
|
11
app/SSH/Services/Database/scripts/postgresql/install-15.sh
Normal file
11
app/SSH/Services/Database/scripts/postgresql/install-15.sh
Normal file
@ -0,0 +1,11 @@
|
||||
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
|
||||
|
||||
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get update -y
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get install postgresql-15 -y
|
||||
|
||||
systemctl status postgresql
|
||||
|
||||
sudo -u postgres psql -c "SELECT version();"
|
11
app/SSH/Services/Database/scripts/postgresql/install-16.sh
Normal file
11
app/SSH/Services/Database/scripts/postgresql/install-16.sh
Normal file
@ -0,0 +1,11 @@
|
||||
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
|
||||
|
||||
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get update -y
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get install postgresql-16 -y
|
||||
|
||||
systemctl status postgresql
|
||||
|
||||
sudo -u postgres psql -c "SELECT version();"
|
5
app/SSH/Services/Database/scripts/postgresql/link.sh
Executable file
5
app/SSH/Services/Database/scripts/postgresql/link.sh
Executable file
@ -0,0 +1,5 @@
|
||||
if ! sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE __database__ TO __username__;"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
echo "Linking to __database__ finished"
|
11
app/SSH/Services/Database/scripts/postgresql/restore.sh
Normal file
11
app/SSH/Services/Database/scripts/postgresql/restore.sh
Normal file
@ -0,0 +1,11 @@
|
||||
if ! DEBIAN_FRONTEND=noninteractive unzip __file__.zip; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo -u postgres psql -d __database__ -f __file__.sql; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! rm __file__.sql __file__.zip; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
10
app/SSH/Services/Database/scripts/postgresql/unlink.sh
Executable file
10
app/SSH/Services/Database/scripts/postgresql/unlink.sh
Executable file
@ -0,0 +1,10 @@
|
||||
USER_TO_REVOKE='__username__'
|
||||
|
||||
DATABASES=$(sudo -u postgres psql -t -c "SELECT datname FROM pg_database WHERE datistemplate = false;")
|
||||
|
||||
for DB in $DATABASES; do
|
||||
echo "Revoking privileges in database: $DB"
|
||||
sudo -u postgres psql -d "$DB" -c "REVOKE ALL PRIVILEGES ON DATABASE \"$DB\" FROM $USER_TO_REVOKE;"
|
||||
done
|
||||
|
||||
echo "Privileges revoked from $USER_TO_REVOKE"
|
Reference in New Issue
Block a user