Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Owo Sugiana
/
maintenance
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit da97c5a3
authored
Jun 06, 2021
by
Owo Sugiana
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Di konfigurasi tidak perlu lagi pg_stop dan pg_start
1 parent
edf738bd
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
47 additions
and
17 deletions
.gitignore
CHANGES.txt
README.rst
maintenance.ini
maintenance/__init__.py
maintenance/pg_conf.py
.gitignore
View file @
da97c5a
...
...
@@ -2,3 +2,4 @@ test*
__pycache__
dist
*egg-info
build
CHANGES.txt
View file @
da97c5a
0.6 5-6-2021
------------
- Bug fixed is_mirror() saat Postgres versi 13
- Di konfigurasi tidak perlu lagi pg_stop dan pg_start
0.5.1 19-5-2021
---------------
- Perintah VACUUM tidak lagi dengan opsi FULL karena akan menghapus file yang
...
...
README.rst
View file @
da97c5a
...
...
@@ -5,7 +5,7 @@ memasangnya::
$ python3 -m venv env
$ env/bin/pip install --upgrade pip
$ env/bin/pip install git+https://git.opensipkd.com/sugiana/maintenance
$ env/bin/pip install git+https://git.opensipkd.com/sugiana/maintenance
.git
Buat file konfigurasi ``maintenance.ini``::
...
...
@@ -21,9 +21,6 @@ Buat file konfigurasi ``maintenance.ini``::
systemctl start nginx.service
systemctl start cron.service
pg_stop = systemctl stop postgresql.service
pg_start = systemctl start postgresql.service
pg_lib_dir = /usr/lib/postgresql
pg_conf_dir = /etc/postgresql
...
...
@@ -56,11 +53,10 @@ Buat file konfigurasi ``maintenance.ini``::
handlers = console, file
level = DEBUG
Konfigurasi ini dibuat untuk Debian 8 ke atas yaitu yang sudah menerapkan
``systemd``. Sesuaikan baris ``database`` yang berisi nama database yang akan
di-backup. Baris ``before`` biasanya diisi dengan perintah untuk menghentikan
daemon yang menggunakan database, sedangkan baris ``after`` untuk
menghidupkannya kembali setelah proses backup selesai.
Sesuaikan baris ``database`` yang berisi nama database yang akan di-backup.
Baris ``before`` biasanya diisi dengan perintah untuk menghentikan daemon yang
menggunakan database, sedangkan baris ``after`` untuk menghidupkannya kembali
setelah proses backup selesai.
Selanjutnya jalankan sebagai root::
...
...
@@ -102,7 +98,7 @@ record pada tabel ``log_file``. Jika pada *log file* terdapat beberapa baris
yang sebenarnya sebuah satu-kesatuan seperti pada *Python exception* maka akan
disimpan ke dalam sebuah record saja.
Buatlah databasenya terlebih dahulu
. Buatlah
file konfigurasi ``log2db.ini``::
Buatlah databasenya terlebih dahulu
, lalu buat
file konfigurasi ``log2db.ini``::
[main]
db_url = postgresql://user:pass@localhost:5432/db
...
...
maintenance.ini
View file @
da97c5a
...
...
@@ -10,9 +10,6 @@ after =
systemctl
start
nginx.service
systemctl
start
cron.service
pg_stop
=
systemctl stop postgresql.service
pg_start
=
systemctl start postgresql.service
pg_lib_dir
=
/usr/lib/postgresql
pg_conf_dir
=
/etc/postgresql
...
...
maintenance/__init__.py
View file @
da97c5a
...
...
@@ -55,10 +55,36 @@ def run_event(event):
run
(
script
)
def
is_systemd
():
script
=
'/lib/systemd/system/postgresql.service'
return
os
.
path
.
exists
(
script
)
def
systemd_pg_service
(
todo
):
pg_conf_dir
=
conf
.
get
(
'main'
,
'pg_conf_dir'
)
for
version
in
os
.
listdir
(
pg_conf_dir
):
conf_dir
=
os
.
path
.
join
(
pg_conf_dir
,
version
)
for
cluster
in
os
.
listdir
(
conf_dir
):
cluster_dir
=
os
.
path
.
join
(
conf_dir
,
cluster
)
pg_conf
=
os
.
path
.
join
(
cluster_dir
,
'postgresql.conf'
)
if
is_mirror
(
pg_conf
):
continue
cmd
=
f
'systemctl {todo} postgresql@{version}-{cluster}.service'
run
(
cmd
)
def
old_pg_service
(
todo
):
pg_conf_dir
=
conf
.
get
(
'main'
,
'pg_conf_dir'
)
for
version
in
os
.
listdir
(
pg_conf_dir
):
cmd
=
f
'/etc/init.d/postgresql {todo} {version}'
run_cmd
()
def
pg_service
(
todo
):
var
=
'pg_'
+
todo
cmd
=
conf
.
get
(
'main'
,
var
)
run
(
cmd
)
if
is_systemd
():
systemd_pg_service
(
todo
)
else
:
old_pg_service
(
todo
)
def
pg_stop
():
...
...
@@ -87,7 +113,9 @@ def pg_port(conf_file):
def
is_mirror
(
pg_conf
):
r
=
Reader
(
pg_conf
)
mirror_conf
=
os
.
path
.
join
(
r
[
'data_directory'
],
'recovery.conf'
)
return
os
.
path
.
exists
(
mirror_conf
)
if
os
.
path
.
exists
(
mirror_conf
):
return
True
return
'recovery_target_timeline'
in
r
# Pastikan database server hanya bisa diakses oleh user postgres secara local
...
...
maintenance/pg_conf.py
View file @
da97c5a
...
...
@@ -17,3 +17,6 @@ class Reader:
def
__getitem__
(
self
,
key
):
return
self
.
conf
[
key
]
def
__contains__
(
self
,
key
):
return
key
in
self
.
conf
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment