Cockroach backups. Still defunct. Restore to come (or be manual).
This commit is contained in:
parent
85474cbcd2
commit
bc81921bd7
|
@ -294,7 +294,7 @@ services:
|
||||||
ipv4_address: 10.10.10.83
|
ipv4_address: 10.10.10.83
|
||||||
|
|
||||||
cockroach:
|
cockroach:
|
||||||
image: cockroachdb/cockroach:v20.1.10
|
image: cockroachdb/cockroach:v20.2.3
|
||||||
container_name: cockroach
|
container_name: cockroach
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
|
@ -303,8 +303,28 @@ services:
|
||||||
- ./docker/data/cockroach/sqlite:/cockroach/cockroach-data
|
- ./docker/data/cockroach/sqlite:/cockroach/cockroach-data
|
||||||
- ./docker/cockroach/certs:/certs
|
- ./docker/cockroach/certs:/certs
|
||||||
ports:
|
ports:
|
||||||
- "4080:8080"
|
- "4080:8080" # TODO Remove this once the setup is finalized.
|
||||||
- "26257:26257"
|
- "26257:26257"
|
||||||
networks:
|
networks:
|
||||||
shared:
|
shared:
|
||||||
ipv4_address: 10.10.10.84
|
ipv4_address: 10.10.10.84
|
||||||
|
|
||||||
|
# This container starts a simple unsecured file server, so cockroach can write
|
||||||
|
# its backups to it. By default, python's http-server doesn't support PUT,
|
||||||
|
# see https://gist.github.com/mildred/67d22d7289ae8f16cae7 for the script
|
||||||
|
# used here.
|
||||||
|
cockroach-backup:
|
||||||
|
image: python:3.9-buster
|
||||||
|
container_name: cockroach-backup
|
||||||
|
command: python /scripts/serve.py --bind=0.0.0.0:3000
|
||||||
|
volumes:
|
||||||
|
- ./docker/cockroach-backup/scripts:/scripts
|
||||||
|
- ./docker/data/cockroach/sqlite:/cockroach
|
||||||
|
expose:
|
||||||
|
- 3000
|
||||||
|
networks:
|
||||||
|
shared:
|
||||||
|
ipv4_address: 10.10.10.85
|
||||||
|
|
||||||
|
|
||||||
|
# TODO https://www.cockroachlabs.com/docs/v20.2/create-schedule-for-backup
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import http.server
|
||||||
|
import os
|
||||||
|
|
||||||
|
class HTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
|
||||||
|
def do_PUT(self):
|
||||||
|
path = self.translate_path(self.path)
|
||||||
|
if path.endswith('/'):
|
||||||
|
self.send_response(405, "Method Not Allowed")
|
||||||
|
self.wfile.write("PUT not allowed on a directory\n".encode())
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
os.makedirs(os.path.dirname(path))
|
||||||
|
except FileExistsError: pass
|
||||||
|
length = int(self.headers['Content-Length'])
|
||||||
|
with open(path, 'wb') as f:
|
||||||
|
f.write(self.rfile.read(length))
|
||||||
|
self.send_response(201, "Created")
|
||||||
|
self.end_headers()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('--bind', '-b', default='0.0.0.0', metavar='ADDRESS',
|
||||||
|
help='Specify alternate bind address '
|
||||||
|
'[default: all interfaces]')
|
||||||
|
parser.add_argument('port', action='store',
|
||||||
|
default=3000, type=int,
|
||||||
|
nargs='?',
|
||||||
|
help='Specify alternate port [default: 3000]')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
http.server.test(HandlerClass=HTTPRequestHandler, port=args.port, bind=args.bind)
|
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Take the current datetime:
|
||||||
|
DT=`date +%Y-%m-%d`
|
||||||
|
# Create the backup:
|
||||||
|
docker exec cockroach \
|
||||||
|
cockroach sql \
|
||||||
|
--host cockroach:26257 \
|
||||||
|
--certs-dir=/certs \
|
||||||
|
--execute="BACKUP TO 'http://cockroach-backup:3000/cockroach/backups/$DT';"
|
Reference in New Issue