Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Top 10 Use Cases of Vibe Coding in Large-Scale Node.js Applications

      September 3, 2025

      Cloudsmith launches ML Model Registry to provide a single source of truth for AI models and datasets

      September 3, 2025

      Kong Acquires OpenMeter to Unlock AI and API Monetization for the Agentic Era

      September 3, 2025

      Microsoft Graph CLI to be retired

      September 2, 2025

      ‘Cronos: The New Dawn’ was by far my favorite experience at Gamescom 2025 — Bloober might have cooked an Xbox / PC horror masterpiece

      September 4, 2025

      ASUS built a desktop gaming PC around a mobile CPU — it’s an interesting, if flawed, idea

      September 4, 2025

      Hollow Knight: Silksong arrives on Xbox Game Pass this week — and Xbox’s September 1–7 lineup also packs in the horror. Here’s every new game.

      September 4, 2025

      The Xbox remaster that brought Gears to PlayStation just passed a huge milestone — “ending the console war” and proving the series still has serious pulling power

      September 4, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Magento (Adobe Commerce) or Optimizely Configured Commerce: Which One to Choose

      September 4, 2025
      Recent

      Magento (Adobe Commerce) or Optimizely Configured Commerce: Which One to Choose

      September 4, 2025

      Updates from N|Solid Runtime: The Best Open-Source Node.js RT Just Got Better

      September 3, 2025

      Scale Your Business with AI-Powered Solutions Built for Singapore’s Digital Economy

      September 3, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      ‘Cronos: The New Dawn’ was by far my favorite experience at Gamescom 2025 — Bloober might have cooked an Xbox / PC horror masterpiece

      September 4, 2025
      Recent

      ‘Cronos: The New Dawn’ was by far my favorite experience at Gamescom 2025 — Bloober might have cooked an Xbox / PC horror masterpiece

      September 4, 2025

      ASUS built a desktop gaming PC around a mobile CPU — it’s an interesting, if flawed, idea

      September 4, 2025

      Hollow Knight: Silksong arrives on Xbox Game Pass this week — and Xbox’s September 1–7 lineup also packs in the horror. Here’s every new game.

      September 4, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: Back Up for a Moment

    CodeSOD: Back Up for a Moment

    July 14, 2025

    James‘s team has a pretty complicated deployment process implemented as a series of bash scripts. The deployment is complicated, the scripts doing the deployment are complicated, and failures mid-deployment are common. That means they need to gracefully roll back, and they way they do that is by making backup copies of the modified files.

    This is how they do that.

    DATE=`<span class="hljs-built_in">date</span> <span class="hljs-string">'+%Y%m%d'</span>`
    BACKUPDIR=`<span class="hljs-built_in">dirname</span> <span class="hljs-variable">${DESTINATION}</span>`/backup
    <span class="hljs-keyword">if</span> [ ! -d <span class="hljs-variable">$BACKUPDIR</span> ]
    <span class="hljs-keyword">then</span>
            <span class="hljs-built_in">echo</span> <span class="hljs-string">"Creating backup directory ..."</span>
            <span class="hljs-built_in">mkdir</span> -p <span class="hljs-variable">$BACKUPDIR</span>
    <span class="hljs-keyword">fi</span>
    FILENAME=`<span class="hljs-built_in">basename</span> <span class="hljs-variable">${DESTINATION}</span>`
    BACKUPFILETYPE=<span class="hljs-variable">${BACKUPDIR}</span>/<span class="hljs-variable">${FILENAME}</span>.<span class="hljs-variable">${DATE}</span>
    BACKUPFILE=<span class="hljs-variable">${BACKUPFILETYPE}</span>-1
    <span class="hljs-keyword">if</span> [ -f <span class="hljs-variable">${BACKUPFILE}</span> ] || [ -f <span class="hljs-variable">${BACKUPFILE}</span>.gz ] ; <span class="hljs-keyword">then</span> BACKUPFILE=<span class="hljs-variable">${BACKUPFILETYPE}</span>-2 ; <span class="hljs-keyword">fi</span>
    <span class="hljs-keyword">if</span> [ -f <span class="hljs-variable">${BACKUPFILE}</span> ] || [ -f <span class="hljs-variable">${BACKUPFILE}</span>.gz ] ; <span class="hljs-keyword">then</span> BACKUPFILE=<span class="hljs-variable">${BACKUPFILETYPE}</span>-3 ; <span class="hljs-keyword">fi</span>
    <span class="hljs-keyword">if</span> [ -f <span class="hljs-variable">${BACKUPFILE}</span> ] || [ -f <span class="hljs-variable">${BACKUPFILE}</span>.gz ] ; <span class="hljs-keyword">then</span> BACKUPFILE=<span class="hljs-variable">${BACKUPFILETYPE}</span>-4 ; <span class="hljs-keyword">fi</span>
    <span class="hljs-keyword">if</span> [ -f <span class="hljs-variable">${BACKUPFILE}</span> ] || [ -f <span class="hljs-variable">${BACKUPFILE}</span>.gz ] ; <span class="hljs-keyword">then</span> BACKUPFILE=<span class="hljs-variable">${BACKUPFILETYPE}</span>-5 ; <span class="hljs-keyword">fi</span>
    <span class="hljs-keyword">if</span> [ -f <span class="hljs-variable">${BACKUPFILE}</span> ] || [ -f <span class="hljs-variable">${BACKUPFILE}</span>.gz ] ; <span class="hljs-keyword">then</span> BACKUPFILE=<span class="hljs-variable">${BACKUPFILETYPE}</span>-6 ; <span class="hljs-keyword">fi</span>
    <span class="hljs-keyword">if</span> [ -f <span class="hljs-variable">${BACKUPFILE}</span> ] || [ -f <span class="hljs-variable">${BACKUPFILE}</span>.gz ] ; <span class="hljs-keyword">then</span> BACKUPFILE=<span class="hljs-variable">${BACKUPFILETYPE}</span>-7 ; <span class="hljs-keyword">fi</span>
    <span class="hljs-keyword">if</span> [ -f <span class="hljs-variable">${BACKUPFILE}</span> ] || [ -f <span class="hljs-variable">${BACKUPFILE}</span>.gz ] ; <span class="hljs-keyword">then</span> BACKUPFILE=<span class="hljs-variable">${BACKUPFILETYPE}</span>-8 ; <span class="hljs-keyword">fi</span>
    <span class="hljs-keyword">if</span> [ -f <span class="hljs-variable">${BACKUPFILE}</span> ] || [ -f <span class="hljs-variable">${BACKUPFILE}</span>.gz ] ; <span class="hljs-keyword">then</span> BACKUPFILE=<span class="hljs-variable">${BACKUPFILETYPE}</span>-9 ; <span class="hljs-keyword">fi</span>
    <span class="hljs-keyword">if</span> [ -f <span class="hljs-variable">${BACKUPFILE}</span> ] || [ -f <span class="hljs-variable">${BACKUPFILE}</span>.gz ] ; <span class="hljs-keyword">then</span>
    <span class="hljs-built_in">cat</span> <<<span class="hljs-string">EOF
    You have already had 9 rates releases in one day.
    
    ${BACKUPFILE} already exists, do it manually !!!
    EOF</span>
    <span class="hljs-built_in">exit</span> 2
    <span class="hljs-keyword">fi</span>
    

    Look, I know that loops in bash can be annoying, but they’re not that annoying.

    This code creates a backup directory (if it doesn’t already exist), and then creates a file name for the file we’re about to backup, in the form OriginalName.Ymd-n.gz. It tests to see if this file exists, and if it does, it increments n by one. It does this until either it finds a file name that doesn’t exist, or it hits 9, at which point it gives you a delightfully passive aggressive message:

    You have already had 9 rates releases in one day.
    ${BACKUPFILE} already exists, do it manually !!!

    Yeah, do it manually. Now, admittedly, I don’t think a lot of folks want to do more than 9 releases in a given day, but there’s no reason why they couldn’t just keep trying until they find a good filename. Or even better, require each release to have an identifier (like the commit or build number or whatever) and then use that for the filenames.

    Of course, just fixing this copy doesn’t address the real WTF, because we laid out the real WTF in the first paragraph: deployment is a series of complicated bash scripts doing complicated steps that can fail all the time. I’ve worked in places like that, and it’s always a nightmare. There are better tools! Our very own Alex has his product, of course, but there are a million ways to get your builds repeatable and reliable that don’t involve BuildMaster but also don’t involve fragile scripts. Please, please use one of those.

    [Advertisement] Plan Your .NET 9 Migration with Confidence
    Your journey to .NET 9 is more than just one decision.Avoid migration migraines with the advice in this free guide. Download Free Guide Now!

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleCritical Vulnerability in Anthropic’s MCP Exposes Developer Machines to Remote Exploits
    Next Article Rilasciata GParted Live Live 1.7.0-8: Essenziale per la Gestione delle Partizioni

    Related Posts

    News & Updates

    ‘Cronos: The New Dawn’ was by far my favorite experience at Gamescom 2025 — Bloober might have cooked an Xbox / PC horror masterpiece

    September 4, 2025
    News & Updates

    ASUS built a desktop gaming PC around a mobile CPU — it’s an interesting, if flawed, idea

    September 4, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    Intel’s new CEO requests “brutal honesty” from partners in his first keynote speech — Determined to build a “world-class” foundry

    News & Updates

    CVE-2025-4897 – Tenda A15 HTTP POST Request Handler Buffer Overflow

    Common Vulnerabilities and Exposures (CVEs)

    The Battlefield 6 PC system requirements are here in time for Open Beta, and they’re kind, too — here are the specs you’ll need to run the explosive FPS

    News & Updates

    CVE-2025-53937 – WeGIA SQL Injection Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    Shokz joins in on the clip-on earbud craze, releasing its most advanced (and expensive) earbuds yet

    April 29, 2025

    The new OpenDots One take direct aim at competitors as more audio brands announce open-ear…

    New Witcher 3 Xbox controllers look like they came straight out of the game

    May 23, 2025

    CVE-2025-37834 – Linux Kernel: Dirty Swapcache Page Reclamation Vulnerability

    May 8, 2025

    How to Know When You Need Mental Help: Signs You Shouldn’t Ignore

    April 28, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.