Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restore .bak files

Tags:

linux

bash

shell

I ran a perl script using

perl -p -i.bak -e "..." *.sh dir/*.sh

This created a copy of every file like

script.sh
script.sh.bak

I now want to restore from the .bak files. How can I do this easily?

like image 539
Baruch Avatar asked May 29 '12 07:05

Baruch


People also ask

What is a BAK file and how do I open it?

These backup files have names ending with the ". bak" file extension, and you use them to restore database backups through Microsoft SQL Server. by navigating to the backup utility and loading the BAK file as a restoration medium, you can open the file and restore the database.

Is .bak a backup file?

In computing, ". bak" is a filename extension commonly used to signify a backup copy of a file. When a program is about to overwrite an existing file (for example, when the user saves the document they are working on), the program may first make a copy of the existing file, with . bak appended to the filename.

What is a .BAK file database?

A file with . bak extension is usually a backup file that is used by different software tools to store backups of data. From database perspective, a BAK file is used by Microsoft SQL Server for storing the contents of a database.


2 Answers

for file in *.sh.bak dir/*.sh.bak; do cp "$file" "${file//.bak}"; done

Or you could use mv instead of cp.

like image 81
Dennis Williamson Avatar answered Nov 09 '22 10:11

Dennis Williamson


find -name '*.bak'|sed 's:.bak$::'|xargs -n 1 -I % cp %.bak %

like image 2
Op De Cirkel Avatar answered Nov 09 '22 10:11

Op De Cirkel