1"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[6868],{3905:(e,t,a)=>{a.d(t,{Zo:()=>u,kt:()=>k});var r=a(7294);function n(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function o(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,r)}return a}function s(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?o(Object(a),!0).forEach((function(t){n(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):o(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function l(e,t){if(null==e)return{};var a,r,n=function(e,t){if(null==e)return{};var a,r,n={},o=Object.keys(e);for(r=0;r<o.length;r++)a=o[r],t.indexOf(a)>=0||(n[a]=e[a]);return n}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r<o.length;r++)a=o[r],t.indexOf(a)>=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(n[a]=e[a])}return n}var c=r.createContext({}),p=function(e){var t=r.useContext(c),a=t;return e&&(a="function"==typeof e?e(t):s(s({},t),e)),a},u=function(e){var t=p(e.components);return r.createElement(c.Provider,{value:t},e.children)},i="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var a=e.components,n=e.mdxType,o=e.originalType,c=e.parentName,u=l(e,["components","mdxType","originalType","parentName"]),i=p(a),m=n,k=i["".concat(c,".").concat(m)]||i[m]||d[m]||o;return a?r.createElement(k,s(s({ref:t},u),{},{components:a})):r.createElement(k,s({ref:t},u))}));function k(e,t){var a=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var o=a.length,s=new Array(o);s[0]=m;var l={};for(var c in t)hasOwnProperty.call(t,c)&&(l[c]=t[c]);l.originalType=e,l[i]="string"==typeof e?e:n,s[1]=l;for(var p=2;p<o;p++)s[p]=a[p];return r.createElement.apply(null,s)}return r.createElement.apply(null,a)}m.displayName="MDXCreateElement"},5444:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>k,frontMatter:()=>l,metadata:()=>p,toc:()=>i});var r=a(7462),n=a(3366),o=(a(7294),a(3905)),s=["components"],l={id:"db-backup",title:"Databases Backup and Restore"}
1,c=void 0,p={unversionedId:"infrastructure/db-backup",id:"infrastructure/db-backup",title:"Databases Backup and Restore",description:"Databases Backup and Restore",source:"@site/docs/infrastructure/database-backups.md",sourceDirName:"infrastructure",slug:"/infrastructure/db-backup",permalink:"/docs/infrastructure/db-backup",draft:!1,editUrl:"https://gitlab.com/minds/docs/edit/master/docs/docs/infrastructure/database-backups.md",tags:[],version:"current",lastUpdatedBy:"Zack Wynne",lastUpdatedAt:1698126701,formattedLastUpdatedAt:"Oct 24, 2023",frontMatter:{id:"db-backup",title:"Databases Backup and Restore"},sidebar:"tutorialSidebar",previous:{title:"Infrastructure",permalink:"/docs/category/infrastructure"},next:{title:"Cloud Access",permalink:"/docs/infrastructure/cloud-access"}},u={},i=[{value:"Databases Backup and Restore",id:"databases-backup-and-restore",level:2},{value:"Vitess",id:"vitess",level:3},{value:"Backup",id:"backup",level:4},{value:"Restore",id:"restore",level:4},{value:"Postgres",id:"postgres",level:3},{value:"MongoDB",id:"mongodb",level:3},{value:"Backup",id:"backup-1",level:4},{value:"Restore",id:"restore-1",level:4}],d={toc:i},m="wrapper";function k(e){var t=e.components,a=(0,n.Z)(e,s);return(0,o.kt)(m,(0,r.Z)({},d,a,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("h2",{id:"databases-backup-and-restore"},"Databases Backup and Restore"),(0,o.kt)("p",null,"We make use of several different databases with different procedures for taking and restoring backups."),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},(0,o.kt)("em",{parentName:"strong"},"NOTE")),": In order to access a database running in Kubernetes, you can use port-forwarding with ",(0,o.kt)("inlineCode",{parentName:"p"},"kubectl"),". For example:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-bash"},'kubectl get svc -n "${NAMESPACE}" # Find the K8s service name\nkubectl port-forward "svc/${SERVICE}" -n "${NAMESPACE}" "${LOCALHOST_PORT}:${REMOTE_PORT}"\n')),(0,o.kt)("h3",{id:"vitess"},"Vitess"),(0,o.kt)("h4",{id:"backup"},"Backup"),(0,o.kt)("p",null,"See also the ",(0,o.kt)("a",{parentName:"p",href:"https://vitess.io/docs/16.0/reference/programs/vtctldclient/vtctldclient_backupshard/"},"official documentation")," for this command."),(0,o.kt)("p",null,"Autmated backups are taken periodically for both Minds and Mautic keyspaces."),(0,o.kt)("p",null,"Vitess backups are stored in Oracle OSS, and can be initiated using ",(0,o.kt)("inlineCode",{parentName:"p"},"vtctlclient"),":"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-bash"},'vtctldclient --server "${VTCTLD_SERVER}" BackupShard "${KEYSPACE}/${SHARD}"\n')),(0,o.kt)("p",null,"Note that when taking a backup for Mautic, you will need to use the ",(0,o.kt)("inlineCode",{parentName:"p"},"--allow-primary")," flag. This is due to the fact that Mautic currently uses a single tablet."),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-bash"},'vtctldclient --server "${VTCTLD_SERVER}" BackupShard --allow-primary "mautic/-"\n')),(0,o.kt)("h4",{id:"restore"},"Restore"),(0,o.kt)("p",null,"See also the ",(0,o.kt)("a",{parentName:"p",href:"https://vitess.io/docs/16.0/reference/programs/vtctldclient/vtctldclient_restorefrombackup/"},"official documentation")," for this command."),(0,o.kt)("p",null,"New tablets will automatically be restored from the latest backup. In order to manually restore a tablet using a specific backup, use ",(0,o.kt)("inlineCode",{parentName:"p"},"vtctldclient"),":"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-bash"},'DATE=YYYY-mm-DD.HHMMSS vtctldclient --server "${VTCTLD_SERVER}" RestoreFromBackup --backup-timestamp "${DATE}" "${TABLET_ALIAS}"\n')),(0,o.kt)("h3",{id:"postgres"},"Postgres"),(0,o.kt)("p",null,"See also the ",(0,o.kt)("a",{parentName:"p",href:"https://www.postgresql.org/docs/current/backup-dump.html"},"official documentation")," for Postgres backups."),(0,o.kt)("p",null,"Like Vitess, most Postgres databases will have automated backups taken periodically. In order to backup manually, you can use ",(0,o.kt)("inlineCode",{parentName:"p"},"pg_dump")," or ",(0,o.kt)("inlineCode",{parentName:"p"},"pg_dumpall"),"."),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-bash"},'pg_dump -C -h "${DB_HOST}" -p "${DB_PORT}" -d "${DATABASE}" > backup.sql\n\n# Or\n\npg_dumpall -C -h "${DB_HOST}" -p "${DB_PORT}" > backup_all.sql\n')),(0,o.kt)("p",null,"Then, you can restore the dump using psql:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-bash"},'psql -h "${DB_HOST}" -p "${DB_PORT}" < backup.sql\n')),(0,o.kt)("h3",{id:"mongodb"},"MongoDB"),(0,o.kt)("h4",{id:"backup-1"},"Backup"),(0,o.kt)("p",null,"See also the ",(0,o.kt)("a",{parentName:"p",href:"https://www.mongodb.com/docs/manual/tutorial/backup-and-restore-tools"},"official documentation")," for these commands."),(0,o.kt)("p",null,"To manually take a MongoDB backup using ",(0,o.kt)("inlineCode",{parentName:"p"},"mongodump"),":"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre"},"mongodump \\\n --host=${DATABASE_HOST} \\\n --port=${DATABSE_PORT} \\\n --username=${USER} \\\n --password=${PASSWORD} \\\n --out=/tmp/mongo-backup\n")),(0,o.kt)("h4",{id:"restore-1"},"Restore"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre"},"mongorestore \\\n --host=${DATABASE_HOST} \\\n --port=${DATABSE_PORT} \\\n --username=${USER} \\\n --password=${PASSWORD} \\\n --authenticationDatabase=admin \\\n /tmp/mongo-backup\n")))}k.isMDXComponent=!0}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.