Understanding the backup script – first steps
Now that we know what a script can look like, we can start writing one. You can use your favorite console editor or IDE to do this. Let’s create an empty file named run_backups.sh
and change its permissions so that they’re executable:
admin@myhome:~$ touch run_backups.sh && chmod +x run_backups.sh admin@myhome:~$ ls -l run_backups.sh -rwxr-xr-x 1 admin admin 0 Dec 1 15:56 run_backups.sh
It’s an empty file, so we’ll need to add a basic database backup command and proceed from there. We won’t be covering granting this script access to a database. We will be backing up a PostgreSQL database and using the pg_dump
tool for that purpose.
Let’s input a shebang line and a pg_dump
command call in our base script:
#!/usr/bin/env bash pg_dump mydatabase > mydatabase.sql
To execute this script, we’ll need to start the following...