Temporary backup of a few files

Now, calm down, we are not talking about tar(1) or cpio(1) backups. Sometimes, there is a need to make a temporary copy of a few files and then copy them back to original filenames. Let’s say you have a directory with few config files and you want to copy each config file to filename.orig, and then, later, restore it to the original name. Here is how you can do it…Backup



#!/bin/bash

# Repeat for all .conf files... (leave just * if you want all files)

for CONFIG in *.conf

do

# Backup

cp $CONFIG $CONFIG.orig

done


Restore



#!/bin/bash

# Repeat for all .orig files...

for CONFIG in *.orig

do

# Restore...

# Note #1: these are single BACK quotes

# Note #2: use -f optin for cp if you want to overwrite originals

cp $CONFIG `basename $CONFIG .orig`

done


Leave a Comment