Code Monkey home page Code Monkey logo

simpleremotebackup.sh's Introduction

simpleremotebackup.sh

A simple backup script to copy a local directory via sftp protocol to a remote server, using the program lftp.

Have fun, but use this script at your own risk! No warranties at all.

Optional creation of sourcedir's name as target's basedir

It is possible to have the sourcedir's basename be created on the target side too. Or to just copy the contents of sourcedir to the target server. See the example below (TGTCREATEBASEDIR).

Optional versioning strategies (VERSIONDIR)

  • no versioning, one target directory
  • one subdirectory for every date (YYYY-MM-DD)
  • one subdirectory for every day of week (1..7)
  • one subdirectory for every day of week (Mon..Sun, by locale)
  • one subdirectory per week (W01..W53) with sub-subdirectories per day of week (1..7)
  • one subdirectory per week (W01..W53) with sub-subdirectories per day of week (Mon..Sun, by locale)
  • one subdirectory per month (01..12) with sub-subdirectories per day (01..31)

Configuration

The above mentioned different behaviors can be configured right within the scripts sourceode. There are some more details explained.

Examples

With two files in 'SRCDIR' '.../data' to be saved on 'Sunday Mar 6 2022' the above types of VERSIONDIR would produce the following structures in the target directory 'TGTROOTDIR':

                          with
  TGTCREATEBASEDIR=no                 TGTCREATEBASEDIR=yes


  ├── file1.txt                       └── data
  ├── file2.txt                           ├── file1.txt
                                          └── file2.txt

  ├── 2022-03-06                      ├── 2022-03-06
  │   ├── file1.txt                   │   └── data
  │   └── file2.txt                   │       ├── file1.txt
                                      │       └── file2.txt

  ├── 7                               ├── 7
  │   ├── file1.txt                   │   └── data
  │   └── file2.txt                   │       ├── file1.txt
                                      │       └── file2.txt

  ├── Sun                             ├── Sun
  │   ├── file1.txt                   │   └── data
  │   └── file2.txt                   │       ├── file1.txt
                                      │       └── file2.txt

  ├── W09                             ├── W09
  │   └── 7                           │   └── 7
  │       ├── file1.txt               │       └── data
          └── file2.txt               │           ├── file1.txt
                                      │           └── file2.txt

  ├── W09                             ├── W09
  │   └── Sun                         │   └── Sun
  │       ├── file1.txt               │       └── data
          └── file2.txt               │           ├── file1.txt
                                      │           └── file2.txt

  ├── M03                             ├── M03
  │   └── 06                          │   └── 06
  │       ├── file1.txt               │       └── data
  │       └── file2.txt               │           ├── file1.txt
                                      │           └── file2.txt

Notes

  • The possible final message from lftp, "To be removed: ..." denotes some older/other data in the target directory LFTP_DIR. That data could be automatically deleted by lftp with the additional option

    --delete in the scripts variable LFTP_CMD.

    BUT BE VERY CAREFUL or all other parallel backups/data are/is gone when done wrong! It's like an rm -r * in the current LFTP_DIR and then copying the new data there. When changing target pathes the rating what is current and what is "old" might not always be obvious - at least for the commands...

  • When connecting to a remote server for the first time, lftp might complain or hang.
    Please use an initial manual ssh user@server to complete the "known-hosts" dialog.
    That should be fixed now, but I'll keep this note here.

simpleremotebackup.sh's People

Contributors

gchriz avatar

Stargazers

framp avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.