DevOps Automation: Website Backup Script with SSH

🖥️ Day 10 of #100DaysOfDevOps — Writing my first website backup automation script Today's task: write a bash script that automatically zips a website's media directory and copies it to a remote storage server — with zero password prompts and zero manual steps. The complete script: #!/bin/bash # Zip the media directory zip -r /backup/xfusioncorp_media.zip /var/www/html/media # Copy to storage server (passwordless SSH) scp /backup/xfusioncorp_media.zip natasha@ststor01:/backup/ Two lines. But here's everything that had to be in place for those two lines to work: → #!/bin/bash (shebang) Tells the OS which interpreter to run this file with. Without it, nothing works. → zip -r The -r flag means recursive — it includes every file and subfolder inside the media directory. Without -r your backup would be empty. → scp over passwordless SSH SCP copies files between servers over SSH. No password prompt because banner's SSH keys are already in natasha's authorized_keys — set up on Day 7. → No sudo inside the script Automation scripts must never use sudo — they break in cron jobs and CI/CD pipelines. Instead I fixed directory ownership before running the script: sudo chown banner:banner /backup sudo chown banner:banner /scripts → chmod +x to make it executable Remember Day 4? A script without execute permission is just a text file. Everything from the past 10 days came together in this one task: Day 4 → chmod to make the script executable Day 7 → SSH keys so scp works silently Day 6 → cron will schedule this script #DevOps #BashScripting #Linux #Automation #Backup #CloudEngineering KodeKloud

  • graphical user interface, text, application, email

To view or add a comment, sign in

Explore content categories