Created
October 21, 2018 00:44
-
-
Save PatPeter/0f91817a7509cf60eef8aa5233ed1440 to your computer and use it in GitHub Desktop.
Fix cPanel backups returned with format %m.%d.%Y_%H-%M-%S
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
backups=~/backups | |
suffix=_website | |
cd $backups | |
for file in `ls $backups` | |
do | |
if [[ $file == "backup-"* && $file == *"$suffix.tar.gz" ]] | |
then | |
dt=$file | |
dt=${dt//backup-/} | |
dt=${dt//$suffix/} | |
dt=${dt//\.tar\.gz/} | |
date=`date -d "$dt" +%Y-%m-%d_%H-%M-%S 2>&1 /dev/null` | |
if [[ $? -ne 0 ]] | |
then | |
continue | |
fi | |
dt=${dt//_/ } | |
dt=${dt//-/:} | |
dt=${dt//./\/} | |
date=`date -d "$dt" +%Y-%m-%d_%H-%M-%S` | |
if [[ -n $date ]] | |
then | |
newname="backup-${date}${suffix}.tar.gz" | |
if [[ $date != $newname ]] | |
then | |
echo mv $file $newname | |
fi | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment