Automate a backup
Write a script that archives a directory, keeps the last seven copies, runs every night and logs what it did.
Open the project: Automate a backupTurning the commands from the Linux skill into Bash scripts that run unattended, handle bad input and fail safely.
Intermediate · 13 topics · 4 projects · about 3 hours of reading
Step 3 of the DevOps engineer roadmap
What a script is, the shebang line, making a script executable, and running it.
Setting and reading variables, quoting, command substitution, and environment variables in scripts.
if, test and [[ ]], comparing strings, numbers and files, and case statements.
for, while and until loops, reading a file line by line, and break and continue.
Default values, trimming and replacing parts of a value, and lengths, without calling other programs.
Positional arguments, shift, options with getopts, reading input, and a usage message.
Defining functions, arguments and return values, local variables, and splitting a script into parts.
Indexed and associative arrays, looping over them, and keeping file names with spaces intact.
Integer maths with $(( )), comparing and formatting numbers and text, and printf.
Exit statuses, checking them, && and ||, writing errors to stderr, and exiting with the right code.
set -euo pipefail, traps and clean-up, temporary files, lock files, and scripts that are safe to run twice.
Tracing a script with set -x, ShellCheck, and finding the line where it goes wrong.
Patterns from scripts that run in production: logging, configuration files, dry runs, and running from cron.
Do these after the topics. Each one runs on your own computer.
Write a script that archives a directory, keeps the last seven copies, runs every night and logs what it did.
Open the project: Automate a backupA script that checks disk, memory, load and services, writes a report, and exits with a status a monitor can act on.
Open the project: Health checkCreate and update user accounts from a CSV file, with validation, a dry-run mode and a summary, safe to run again.
Open the project: Bulk users from a fileRelease a new version of a site into a timestamped directory, switch to it with a symlink, check it, and roll back on failure.
Open the project: Deploy script