<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write(self):
 """Safely write the index data to the index file """

        index_file = self.path
        new_index_file = index_file + '.new'
        bak_index_file = index_file + '.bak'

        if not self._db:
            return

        with open(new_index_file, 'w') as f:
            json.dump(self._db, f, indent=4)

        if exists(index_file):
            copy(index_file, bak_index_file)

        rename(new_index_file, index_file)