Posts

Showing posts from June, 2022

Automate PostgreSql Backup with Cron

  Create The  Postgres Password File The file  .pgpass  in a user’s home directory can contain passwords to be used if the connection requires a password (and no password has been specified otherwise). On Microsoft Windows the file is named  %APPDATA%\postgresql\pgpass.conf  (where  %APPDATA%  refers to the Application Data subdirectory in the user’s profile). Alternatively, the password file to use can be specified using the connection parameter passfile or the environment variable  PGPASSFILE . Let’s see if the  postgres user  already has a password: sudo -u postgres psql select * from pg_authid; If  rolpassword  is empty, set the password: ALTER USER postgres PASSWORD 'mypassword'; \q Create  .pgpass vim ~/.pgpass # Add the following line # hostname:port:database:username:password localhost:*:*:postgres:[password] Add Environment variable  PGPASSFILE export PGPASSFILE= '/root/.pgpass' vim /etc/environment # Add the following line PGPASSFILE= "/root/.pgpass&

Automate borg backups with Cron

Install dependencies To be able send an email from the backup bash command, we have to install mailutils: apt install mailutils Create borg_backup.sh First, create a script which will execute the backups. This could look like the following script and be under  /home/server_backup/scripts/borg_backup.sh . #!/usr/bin/env bash ################################################ #### borg create and borg prune #### #### PLEASE CHECK BACKUP DIRECTORIES #### ################################################ ## ## Set environment variables ## ## if you don't use the standard SSH key, ## you have to specify the path to the key like this export BORG_RSH= "ssh -i /root/.ssh/id_rsa_borg" ## You can save your borg passphrase in an environment ## variable, so you don't need to type it in when using borg # export BORG_PASSPHRASE="top_secret_passphrase" # ACTIVATE VENV source /usr/ local /venvs/borg-env/bin/activate ## ## Set some var