Skip to content

Instantly share code, notes, and snippets.

@pherjung
Last active April 14, 2022 07:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pherjung/3acf8ed0b0888b772068a191053c820d to your computer and use it in GitHub Desktop.
Save pherjung/3acf8ed0b0888b772068a191053c820d to your computer and use it in GitHub Desktop.
#!/bin/bash
# Test if file exists
backups=$(ls -1 $1/|wc -l)
if [ $backups -gt 0 ]
then
rsync -a --remove-source-files --chown=defaultuser:defaultuser $1/ $2
else
exit
fi
# Count amount backup
files=$(ls -1 $2| wc -l)
# Keep only two latest backup
if [ $files -gt 2 ]
then
cd $2
rm $(ls -1t $2| sed -n '3,$p')
fi
@pherjung
Copy link
Author

pherjung commented Apr 8, 2022

How to use it:

./mvBackup.sh /directory/where/backup/are/saved /where/to/move/backup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment